Неконтролируемые исключения
Неверное использование ссылки null
Неверное использование ссылки null
Неверное приведение
Операция не поддерживается
Некорректное состояние
Выход за пределы массива
Неверный аргумент
Ошибка преобразования в число
Контролируемые исключения
Определение класса не найдено во время выполнения
Файл не найден
Файл не найден
Ошибка доступа к СУБД
Ошибка доступа к СУБД
Неправильно сформированный URL
Ошибки (Errors)
Определение класса не найдено
Определение класса не найдено
Определение класса не найдено
Переполнение стека
Недостаточный объём памяти
751.13K
Category: programmingprogramming

Исключения. Стандартные исключения

1.

2.

VI. Исключения
3. Стандартные исключения
2

3. Неконтролируемые исключения

Исключение
Описание
NullPointerException
Неверное использование ссылки null (разыменование нулевой ссылки)
ClassCastException
Неверное приведение ссылочных типов
OperationNotSupportedException
Операция не поддерживается
IllegalStateException
Некорректное состояние
ArrayIndexOutOfBoundsException
Выход за пределы массива
IllegalArgumentException
Неверный аргумент
NumberFormatException
Ошибка преобразования в число
3

4. Неверное использование ссылки null

4

5. Неверное использование ссылки null

public
public class
class NullPointerExceptionDemo
NullPointerExceptionDemo {{
public
public static
static void
void main(String[]
main(String[] args)
args) {{
String[]
String[] staff
staff == {"Harry
{"Harry Hacker",
Hacker", "Tonny
"Tonny Tester",
Tester", "Eve
"Eve Engineer",
Engineer", null,
null, "Carl
"Carl Cracker"};
Cracker"};
for(String
for(String name
name :: staff){
staff){
System.out.println("Hello
System.out.println("Hello "" ++ name.toUpperCase());
name.toUpperCase());
}}
}}
}}
System.out.println();
System.out.println();
System.out.println("Total
System.out.println("Total staff
staff members:
members: "" ++ staff.length);
staff.length);
Hello
Hello HARRY
HARRY HACKER
HACKER
Hello
TONNY
TESTER
Hello TONNY TESTER
Hello
Hello EVE
EVE ENGINEER
ENGINEER
Exception
Exception in
in thread
thread "main"
"main" java.lang.NullPointerException
java.lang.NullPointerException
at
at standard.NullPointerExceptionDemo.main(NullPointerExceptionDemo.java:10)
standard.NullPointerExceptionDemo.main(NullPointerExceptionDemo.java:10)
5

6. Неверное приведение

public
public class
class ClassCastExceptionDemo
ClassCastExceptionDemo {{
public
public static
static void
void main(String[]
main(String[] args)
args) {{
}}
}}
Object
Object obj
obj == new
new Integer(10);
Integer(10);
System.out.println("Casting
System.out.println("Casting Integer
Integer to
to String.....");
String.....");
String
String str
str =(String)
=(String) obj;
obj;
System.out.println("This
System.out.println("This line
line will
will never
never be
be printed");
printed");
Casting
Casting Integer
Integer to
to String.....
String.....
Exception
in
thread
Exception in thread "main"
"main" java.lang.ClassCastException:
java.lang.ClassCastException: java.lang.Integer
java.lang.Integer cannot
cannot be
be cast
cast to
to java.lang.String
java.lang.String
at
at standard.ClassCastExceptionDemo.main(ClassCastExceptionDemo.java:9)
standard.ClassCastExceptionDemo.main(ClassCastExceptionDemo.java:9)
6

7. Операция не поддерживается

public
public class
class OperationNotSupportedExceptionDemo
OperationNotSupportedExceptionDemo {{
public
public static
static void
void main(String[]
main(String[] args)
args) {{
Set<String>
Set<String> greetings
greetings == Collections.singleton("Hello");
Collections.singleton("Hello");
for(String
for(String greeting
greeting :: greetings){
greetings){
System.out.println(greeting);
System.out.println(greeting);
}}
greetings.add("Hi");
greetings.add("Hi");
greetings.add("Good
greetings.add("Good morning");
morning");
}}
}}
for(String
for(String greeting
greeting :: greetings){
greetings){
System.out.println(greeting);
System.out.println(greeting);
}}
Hello
Hello
Exception
Exception in
in thread
thread "main"
"main" java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
at
at java.util.AbstractCollection.add(Unknown
java.util.AbstractCollection.add(Unknown Source)
Source)
at
at standard.OperationNotSupportedExceptionDemo.main(OperationNotSupportedExceptionDemo.java:16)
standard.OperationNotSupportedExceptionDemo.main(OperationNotSupportedExceptionDemo.java:16)
7

8. Некорректное состояние

public
public class
class IllegalStateExceptionDemo
IllegalStateExceptionDemo {{
public
public static
static void
void main(String[]
main(String[] args)
args) {{
Set<String>
Set<String> staff
staff == new
new TreeSet<String>();
TreeSet<String>();
staff.add("Harry
staff.add("Harry Hacker");
Hacker");
staff.add("Tonny
Tester");
staff.add("Tonny Tester");
staff.add("Eve
staff.add("Eve Engineer");
Engineer");
staff.add("Carl
staff.add("Carl Cracker");
Cracker");
Iterator<String>
Iterator<String> iter
iter == staff.iterator();
staff.iterator();
}}
}}
System.out.println(iter.next());
System.out.println(iter.next());
System.out.println(iter.next());
System.out.println(iter.next());
iter.remove();
iter.remove();
iter.remove();
iter.remove();
Carl
Carl Cracker
Cracker
Eve
Eve Engineer
Engineer
Exception
Exception in
in thread
thread "main"
"main" java.lang.IllegalStateException
java.lang.IllegalStateException
at
at java.util.TreeMap$PrivateEntryIterator.remove(TreeMap.java:1119)
java.util.TreeMap$PrivateEntryIterator.remove(TreeMap.java:1119)
at
standard.IllegalStateExceptionDemo.main(IllegalStateExceptionDemo.java:25)
at standard.IllegalStateExceptionDemo.main(IllegalStateExceptionDemo.java:25)
8

9. Выход за пределы массива

public
public class
class IndexOutOfBoundsExceptionDemo
IndexOutOfBoundsExceptionDemo {{
public
public static
static void
void main(String[]
main(String[] args)
args) {{
int[]
int[] anArray
anArray == {{ 0,
0, 100,
100, 200,
200, 300,
300, 400,
400, 500,
500, 600,
600, 700,
700, 800,
800, 900
900 };
};
for
for (int
(int ii == 0;
0; ii <=
<= 10;
10; i++)
i++) {{
}}
}}
}}
System.out.println(anArray[i]);
System.out.println(anArray[i]);
System.out.println();
System.out.println();
System.out.println("Array
System.out.println("Array length
length is:
is: "" ++ anArray.length);
anArray.length);
00
100
100
200
200
300
300
400
400
500
500
600
600
700
700
800
800
900
900
Exception
Exception in
in thread
thread "main"
"main" java.lang.ArrayIndexOutOfBoundsException:
java.lang.ArrayIndexOutOfBoundsException: 10
10
at
standard.IndexOutOfBoundsExceptionDemo.main(IndexOutOfBoundsExceptionDemo.java:11)
at standard.IndexOutOfBoundsExceptionDemo.main(IndexOutOfBoundsExceptionDemo.java:11)
9

10. Неверный аргумент

public
public class
class IllegalArgumentExceptionDemo
IllegalArgumentExceptionDemo {{
public
public static
static void
void main(String[]
main(String[] args)
args) {{
SimpleDateFormat
SimpleDateFormat sdf
sdf == new
new SimpleDateFormat("MM/dd/yyyy
SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
HH:mm:ss");
long
long now
now == System.currentTimeMillis();
System.currentTimeMillis();
System.out.println("Current
System.out.println("Current date
date and
and time:
time: "" ++ sdf.format(now));
sdf.format(now));
sdf
sdf == new
new SimpleDateFormat("Hello
SimpleDateFormat("Hello World:
World: MM/dd/yyyy
MM/dd/yyyy HH:mm:ss");
HH:mm:ss");
now
now == System.currentTimeMillis();
System.currentTimeMillis();
System.out.println("Current
System.out.println("Current date
date and
and time:
time: "" ++ sdf.format(now));
sdf.format(now));
}}
}}
Current
Current date
date and
and time:
time: 04/21/2013
04/21/2013 19:51:03
19:51:03
Exception
in
thread
"main"
java.lang.IllegalArgumentException:
Exception in thread "main" java.lang.IllegalArgumentException: Illegal
Illegal pattern
pattern character
character 'e'
'e'
at
at java.text.SimpleDateFormat.compile(Unknown
java.text.SimpleDateFormat.compile(Unknown Source)
Source)
at
at java.text.SimpleDateFormat.initialize(Unknown
java.text.SimpleDateFormat.initialize(Unknown Source)
Source)
at
at java.text.SimpleDateFormat.<init>(Unknown
java.text.SimpleDateFormat.<init>(Unknown Source)
Source)
at
java.text.SimpleDateFormat.<init>(Unknown
Source)
at java.text.SimpleDateFormat.<init>(Unknown Source)
at
at standard.IllegalArgumentExceptionDemo.main(IllegalArgumentExceptionDemo.java:16)
standard.IllegalArgumentExceptionDemo.main(IllegalArgumentExceptionDemo.java:16)
10

11. Ошибка преобразования в число

public
public class
class NumberFormatExceptionDemo
NumberFormatExceptionDemo {{
public
public static
static void
void main(String[]
main(String[] args)
args) {{
String[]
String[] numbers
numbers
== {"9",
{"9", "25",
"25", "14",
"14", "11",
"11", "33",
"33", "hello
"hello world",
world", "45"};
"45"};
int
int total
total == 0;
0;
}}
}}
for
for (String
(String number
number :: numbers)
numbers) {{
total
total +=
+= Integer.parseInt(number);
Integer.parseInt(number);
System.out.println("Total
System.out.println("Total so
so far:
far: "" ++ total);
total);
}}
Total
Total so
so far:
far: 99
Total
Total so
so far:
far: 34
34
Total
Total so
so far:
far: 48
48
Total
Total so
so far:
far: 59
59
Total
Total so
so far:
far: 92
92
Exception
in
thread
Exception in thread "main"
"main" java.lang.NumberFormatException:
java.lang.NumberFormatException: For
For input
input string:
string: "hello
"hello world"
world"
at
java.lang.NumberFormatException.forInputString(Unknown
Source)
at java.lang.NumberFormatException.forInputString(Unknown Source)
at
at java.lang.Integer.parseInt(Unknown
java.lang.Integer.parseInt(Unknown Source)
Source)
at
at java.lang.Integer.parseInt(Unknown
java.lang.Integer.parseInt(Unknown Source)
Source)
at
at standard.NumberFormatExceptionDemo.main(NumberFormatExceptionDemo.java:12)
standard.NumberFormatExceptionDemo.main(NumberFormatExceptionDemo.java:12)
11

12.

Проверяемые исключения
12

13. Контролируемые исключения

Исключение
Описание
ClassNotFoundException
Определение класса не найдено во время динамической загрузки
FileNotFoundException
Файл не найден
SQLException
Ошибка доступа к СУБД
MalformedURLException
Неправильно сформированный URL
13

14. Определение класса не найдено во время выполнения

public
public class
class ClassNotFoundExceptionDemo
ClassNotFoundExceptionDemo {{
public
public static
static void
void main(String
main(String args[])
args[]) {{
try
try {{
URLClassLoader
URLClassLoader loader
loader == new
new URLClassLoader(new
URLClassLoader(new URL[]
URL[] {{ new
new URL(
URL(
"file://C:/CL/ClassNotFoundException/")
"file://C:/CL/ClassNotFoundException/") });
});
loader.loadClass("DoesNotExist");
loader.loadClass("DoesNotExist");
}} catch
catch (ClassNotFoundException
(ClassNotFoundException e)
e) {{
e.printStackTrace();
e.printStackTrace();
}} catch
catch (MalformedURLException
(MalformedURLException e)
e) {{
e.printStackTrace();
e.printStackTrace();
}}
}}
}}
java.lang.ClassNotFoundException:
java.lang.ClassNotFoundException: DoesNotExist
DoesNotExist
at
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at
at java.security.AccessController.doPrivileged(Native
java.security.AccessController.doPrivileged(Native Method)
Method)
at
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at
java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at
at standard.ClassNotFoundExceptionDemo.main(ClassNotFoundExceptionDemo.java:13)
standard.ClassNotFoundExceptionDemo.main(ClassNotFoundExceptionDemo.java:13)
14

15. Файл не найден

public
public class
class FileNotFoundExceptionDemo
FileNotFoundExceptionDemo {{
public
public static
static void
void main(String[]
main(String[] args)
args) {{
BufferedReader
BufferedReader br
br == null;
null;
try
try {{
String
String sCurrentLine;
sCurrentLine;
br
=
new
br = new BufferedReader(new
BufferedReader(new FileReader("I:\\DoesNotExist.txt"));
FileReader("I:\\DoesNotExist.txt"));
while
while ((sCurrentLine
((sCurrentLine == br.readLine())
br.readLine()) !=
!= null)
null) {{
System.out.println(sCurrentLine);
System.out.println(sCurrentLine);
}}
}} catch
catch (FileNotFoundException
(FileNotFoundException e)
e) {{
e.printStackTrace();
e.printStackTrace();
}} catch
catch (IOException
(IOException e)
e) {{
e.printStackTrace();
e.printStackTrace();
}} finally
finally {{
}}
}}
if
if (br
(br !=
!= null)
null) {{
try
try {{
br.close();
br.close();
}} catch
catch (IOException
(IOException e)
e) {{
e.printStackTrace();
e.printStackTrace();
}}
}}
}}
15

16. Файл не найден

java.io.FileNotFoundException:
java.io.FileNotFoundException: I:\DoesNotExist.txt
I:\DoesNotExist.txt (The
(The system
system cannot
cannot find
find the
the file
file specified)
specified)
at
java.io.FileInputStream.open(Native
Method)
at java.io.FileInputStream.open(Native Method)
at
at java.io.FileInputStream.<init>(FileInputStream.java:120)
java.io.FileInputStream.<init>(FileInputStream.java:120)
at
at java.io.FileInputStream.<init>(FileInputStream.java:79)
java.io.FileInputStream.<init>(FileInputStream.java:79)
at
at java.io.FileReader.<init>(FileReader.java:41)
java.io.FileReader.<init>(FileReader.java:41)
at
at standard.FileNotFoundExceptionDemo.main(FileNotFoundExceptionDemo.java:17)
standard.FileNotFoundExceptionDemo.main(FileNotFoundExceptionDemo.java:17)
16

17. Ошибка доступа к СУБД

public
public class
class SQLExceptionDemo
SQLExceptionDemo {{
static
static final
final String
String DB_URL
DB_URL == "jdbc:derby:C:/otherDirectory/myDB";
"jdbc:derby:C:/otherDirectory/myDB";
static
static final
final String
String USER
USER == "sa";
"sa";
static
static final
final String
String PASS
PASS == "";
"";
public
public static
static void
void main(String[]
main(String[] args)
args) throws
throws SQLException
SQLException {{
Connection
Connection connection
connection == null;
null;
try
try {{
System.out.println("Connecting
System.out.println("Connecting to
to aa selected
selected database...");
database...");
connection
connection == DriverManager.getConnection(DB_URL,
DriverManager.getConnection(DB_URL, USER,
USER, PASS);
PASS);
System.out.println("Connected
System.out.println("Connected to
to the
the database");
database");
}} catch
catch (SQLException
(SQLException e)
e) {{
e.printStackTrace();
e.printStackTrace();
}} finally
finally {{
}}
}}
}}
if
if (connection
(connection !=
!= null)
null) {{
try
try {{
connection.close();
connection.close();
}} catch
catch (SQLException
(SQLException e)
e) {{
e.printStackTrace();
e.printStackTrace();
}}
}}
17

18. Ошибка доступа к СУБД

Connecting
Connecting to
to aa selected
selected database...
database...
java.sql.SQLException:
java.sql.SQLException: Database
Database 'c:/otherDirectory/myDB'
'c:/otherDirectory/myDB' not
not found.
found.
at
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown
org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
Source)
at
org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown
Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown
org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
Source)
at
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown
org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
Source)
at
at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown
org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
Source)
at
at org.apache.derby.impl.jdbc.EmbedConnection.handleDBNotFound(Unknown
org.apache.derby.impl.jdbc.EmbedConnection.handleDBNotFound(Unknown Source)
Source)
at
org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown
Source)
at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source)
at
at org.apache.derby.impl.jdbc.EmbedConnection40.<init>(Unknown
org.apache.derby.impl.jdbc.EmbedConnection40.<init>(Unknown Source)
Source)
at
at org.apache.derby.jdbc.Driver40.getNewEmbedConnection(Unknown
org.apache.derby.jdbc.Driver40.getNewEmbedConnection(Unknown Source)
Source)
at
at org.apache.derby.jdbc.InternalDriver.connect(Unknown
org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
Source)
at
at org.apache.derby.jdbc.Driver20.connect(Unknown
org.apache.derby.jdbc.Driver20.connect(Unknown Source)
Source)
at
org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown
at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source)
Source)
at
java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at
at java.sql.DriverManager.getConnection(DriverManager.java:185)
java.sql.DriverManager.getConnection(DriverManager.java:185)
at
at standard.SQLExceptionDemo.main(SQLExceptionDemo.java:21)
standard.SQLExceptionDemo.main(SQLExceptionDemo.java:21)
Caused
Caused by:
by: java.sql.SQLException:
java.sql.SQLException: Database
Database 'c:/otherDirectory/myDB'
'c:/otherDirectory/myDB' not
not found.
found.
at
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
Source)
at
org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
Source)
...
... 15
15 more
more
18

19. Неправильно сформированный URL

public
public class
class MalformedURLExceptionDemo
MalformedURLExceptionDemo {{
public
public static
static void
void main(String[]
main(String[] args)
args) {{
try
try {{
URL
URL url
url == new
new URL("gttp://www.google.com:80/");
URL("gttp://www.google.com:80/");
BufferedReader
BufferedReader in
in == new
new BufferedReader(new
BufferedReader(new InputStreamReader(url.openStream()));
InputStreamReader(url.openStream()));
String
String line;
line;
while
((line
while ((line == in.readLine())
in.readLine()) !=
!= null)
null) {{
System.out.println(line);
System.out.println(line);
}}
in.close();
in.close();
}} catch
catch (MalformedURLException
(MalformedURLException e)
e) {{
e.printStackTrace();
e.printStackTrace();
}} catch
catch (IOException
(IOException e)
e) {{
e.printStackTrace();
e.printStackTrace();
}}
}}
}}
java.net.MalformedURLException:
java.net.MalformedURLException: unknown
unknown protocol:
protocol: gttp
gttp
at
at java.net.URL.<init>(URL.java:574)
java.net.URL.<init>(URL.java:574)
at
at java.net.URL.<init>(URL.java:464)
java.net.URL.<init>(URL.java:464)
at
java.net.URL.<init>(URL.java:413)
at java.net.URL.<init>(URL.java:413)
at
at standard.MalformedURLExceptionDemo.main(MalformedURLExceptionDemo.java:15)
standard.MalformedURLExceptionDemo.main(MalformedURLExceptionDemo.java:15)
19

20.

Ошибки (Errors)
20

21. Ошибки (Errors)

Исключение
Описание
NoClassDefFoundError
Определение класса не найдено
StackOverflowError
Переполнение стека
OutOfMemoryError
Недостаточный объём памяти
21

22. Определение класса не найдено

public
public class
class NoClassDefFoundErrorDemo
NoClassDefFoundErrorDemo {{
public
public static
static void
void main(String[]
main(String[] args)
args) {{
}}
}}
Student
Student harry
harry == new
new Student("Harry
Student("Harry Hacker",
Hacker", "Applied
"Applied Mathematics");
Mathematics");
System.out.println(harry);
System.out.println(harry);
class
class Student
Student {{
private
private
private
private
String
String
String
String
name;
name;
major;
major;
public
public Student(String
Student(String name,
name, String
String major)
major) {{
this.name
this.name == name;
name;
this.major
this.major == major;
major;
}}
public
public String
String toString()
toString() {{
return
return "Student
"Student [name="
[name=" ++ name
name ++ ",
", major="
major=" ++ major
major ++ "]";
"]";
}}
}}
22

23. Определение класса не найдено

F:\spaces\javase-space\06.Exceptions\bin>dir
F:\spaces\javase-space\06.Exceptions\bin>dir standard
standard
Volume
in
drive
F
has
no
label.
Volume in drive F has no label.
Volume
Volume Serial
Serial Number
Number is
is 58B9-DDFE
58B9-DDFE
Directory
Directory of
of F:\spaces\javase-space\06.Exceptions\bin\standard
F:\spaces\javase-space\06.Exceptions\bin\standard
01/21/2014
01/21/2014
01/21/2014
01/21/2014
01/21/2014
01/21/2014
01/21/2014
01/21/2014
04:23
<DIR>
..
04:23 PM
PM
<DIR>
04:23
<DIR>
..
04:23 PM
PM
<DIR>
..
04:20
747
04:20 PM
PM
747 NoClassDefFoundErrorDemo.class
NoClassDefFoundErrorDemo.class
04:20
745
Student.class
04:20 PM
PM
745 Student.class
Student.class
22 File(s)
1,492
File(s)
1,492 bytes
bytes
22 Dir(s)
40,497,762,304
bytes
Dir(s) 40,497,762,304 bytes free
free
F:\spaces\javase-space\06.Exceptions\bin>java
F:\spaces\javase-space\06.Exceptions\bin>java standard/NoClassDefFoundErrorDemo
standard/NoClassDefFoundErrorDemo
Student
Student [name=Harry
[name=Harry Hacker,
Hacker, major=Applied
major=Applied Mathematics]
Mathematics]
23

24. Определение класса не найдено

F:\spaces\javase-space\06.Exceptions\bin>del
F:\spaces\javase-space\06.Exceptions\bin>del standard\Student.class
standard\Student.class
F:\spaces\javase-space\06.Exceptions\bin>dir
F:\spaces\javase-space\06.Exceptions\bin>dir standard
standard
Volume
Volume in
in drive
drive FF has
has no
no label.
label.
Volume
Serial
Number
is
58B9-DDFE
Volume Serial Number is 58B9-DDFE
Directory
Directory of
of F:\spaces\javase-space\06.Exceptions\bin\standard
F:\spaces\javase-space\06.Exceptions\bin\standard
01/21/2014
01/21/2014
01/21/2014
01/21/2014
01/21/2014
01/21/2014
04:27
<DIR>
..
04:27 PM
PM
<DIR>
04:27
<DIR>
..
04:27 PM
PM
<DIR>
..
04:20
PM
747
NoClassDefFoundErrorDemo.class
04:20 PM
747 NoClassDefFoundErrorDemo.class
11 File(s)
747
File(s)
747 bytes
bytes
22 Dir(s)
Dir(s) 40,497,766,400
40,497,766,400 bytes
bytes free
free
F:\spaces\javase-space\06.Exceptions\bin>java
F:\spaces\javase-space\06.Exceptions\bin>java standard/NoClassDefFoundErrorDemo
standard/NoClassDefFoundErrorDemo
java.lang.NoClassDefFoundError
Exception
in
thread
"main"
java.lang.NoClassDefFoundError:
standard/Student
Exception in thread "main" java.lang.NoClassDefFoundError: standard/Student
standard/Student
at
at standard.NoClassDefFoundErrorDemo.main(NoClassDefFoundErrorDemo.java:6)
standard.NoClassDefFoundErrorDemo.main(NoClassDefFoundErrorDemo.java:6)
Caused
Caused by:
by: java.lang.ClassNotFoundException:
java.lang.ClassNotFoundException: standard.Student
standard.Student
at
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at
java.security.AccessController.doPrivileged(Native
at java.security.AccessController.doPrivileged(Native Method)
Method)
at
java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
java.lang.ClassLoader.loadClass(ClassLoader.java:247)
...
... 11 more
more
F:\spaces\javase-space\06.Exceptions\bin>
F:\spaces\javase-space\06.Exceptions\bin>
24

25. Переполнение стека

public
public class
class StackOverflowErrorDemo
StackOverflowErrorDemo {{
public
public static
static void
void RecursiveSayHello()
RecursiveSayHello() {{
}}
}}
System.out.println("Hello
System.out.println("Hello World!");
World!");
RecursiveSayHello();
RecursiveSayHello();
public
public static
static void
void main(String[]
main(String[] args)
args) {{
RecursiveSayHello();
RecursiveSayHello();
}}
Hello
Hello World!
World!
Hello
World!
Hello World!
Hello
Hello World!
World!
Hello
Hello World!
World!
Exception
Exception in
in thread
thread "main"
"main" java.lang.StackOverflowError
java.lang.StackOverflowError
at
at sun.nio.cs.SingleByte.withResult(Unknown
sun.nio.cs.SingleByte.withResult(Unknown Source)
Source)
at
sun.nio.cs.SingleByte.access$000(Unknown
Source)
at sun.nio.cs.SingleByte.access$000(Unknown Source)
at
at sun.nio.cs.SingleByte$Encoder.encodeArrayLoop(Unknown
sun.nio.cs.SingleByte$Encoder.encodeArrayLoop(Unknown Source)
Source)
at
at sun.nio.cs.SingleByte$Encoder.encodeLoop(Unknown
sun.nio.cs.SingleByte$Encoder.encodeLoop(Unknown Source)
Source)
at
at java.nio.charset.CharsetEncoder.encode(Unknown
java.nio.charset.CharsetEncoder.encode(Unknown Source)
Source)
at
at sun.nio.cs.StreamEncoder.implWrite(Unknown
sun.nio.cs.StreamEncoder.implWrite(Unknown Source)
Source)
at
sun.nio.cs.StreamEncoder.write(Unknown
Source)
at sun.nio.cs.StreamEncoder.write(Unknown Source)
at
at java.io.OutputStreamWriter.write(Unknown
java.io.OutputStreamWriter.write(Unknown Source)
Source)
at
at java.io.BufferedWriter.flushBuffer(Unknown
java.io.BufferedWriter.flushBuffer(Unknown Source)
Source)
at
at java.io.PrintStream.write(Unknown
java.io.PrintStream.write(Unknown Source)
Source)
at
at java.io.PrintStream.print(Unknown
java.io.PrintStream.print(Unknown Source)
Source)
at
at java.io.PrintStream.println(Unknown
java.io.PrintStream.println(Unknown Source)
Source)
at
standard.StackOverflowErrorDemo.RecursiveSayHello(StackOverflowErrorDemo.java:7)
at standard.StackOverflowErrorDemo.RecursiveSayHello(StackOverflowErrorDemo.java:7)
at
at standard.StackOverflowErrorDemo.RecursiveSayHello(StackOverflowErrorDemo.java:8)
standard.StackOverflowErrorDemo.RecursiveSayHello(StackOverflowErrorDemo.java:8)
25

26. Недостаточный объём памяти

public
public class
class OutOfMemoryErrorDemo
OutOfMemoryErrorDemo {{
public
public static
static void
void main(String[]
main(String[] args)
args) {{
int[][]
int[][] bigArray
bigArray == new
new int[10000][];
int[10000][];
for
for (int
(int ii == 0;
0; ii << bigArray.length;
bigArray.length; i++)
i++) {{
}}
}}
}}
bigArray[i]
bigArray[i] == new
new int[1024*256];
int[1024*256];
System.out.println(i
System.out.println(i ++ "" MB
MB used");
used");
239
239 MB
MB used
used
240
MB
used
240 MB used
241
241 MB
MB used
used
242
242 MB
MB used
used
243
243 MB
MB used
used
244
244 MB
MB used
used
245
MB
used
245 MB used
Exception
Exception in
in thread
thread "main"
"main" java.lang.OutOfMemoryError:
java.lang.OutOfMemoryError: Java
Java heap
heap space
space
at
at standard.OutOfMemoryErrorDemo.main(OutOfMemoryErrorDemo.java:11)
standard.OutOfMemoryErrorDemo.main(OutOfMemoryErrorDemo.java:11)
26
English     Русский Rules