Java Reference
In-Depth Information
figure 2.12
Common standard
runtime exceptions
Standard Runtime Exception
Meaning
ArithmeticException
Overflow or integer division by zero.
NumberFormatException
Illegal conversion of String to numeric type.
IndexOutOfBoundsException
Illegal index into an array or String .
NegativeArraySizeException
Attempt to create a negative-length array.
NullPointerException
Illegal attempt to use a null reference.
SecurityException
Run-time security violation.
NoSuchElementException
Failed attempt to obtain “next” item
caught. A notable violation of this principle is NumberFormatException , but
NullPointerException is more typical.
Most exceptions are of the standard checked exception variety. If a
method is called that might either directly or indirectly throw a standard
checked exception, then the programmer must either provide a catch block
for it, or explicitly indicate that the exception is to be propagated by use
of a throws clause in the method declaration. Note that eventually it should
be handled because it is terrible style for main to have a throws
clause. Some of the common standard checked exceptions are shown in
Figure 2.13.
Checked excep-
tions must be han-
dled or listed in a
throws clause.
Errors are virtual machine problems. OutOfMemoryError is the most com-
mon error. Others include InternalError and the infamous UnknownError , in
which the virtual machine has decided that it is in trouble, does not know
why, but does not want to continue. Generally speaking, an Error is unre-
coverable and should not be caught.
Errors are unrecov-
erable exceptions.
figure 2.13
Common standard
checked exceptions
Standard Checked Exception
Meaning
java.io.EOFException
End-of-file before completion of input.
java.io.FileNotFoundException
File not found to open.
java.io.IOException
Includes most I/O exceptions.
InterruptedException
Thrown by the Thread.sleep method.
 
 
Search WWH ::




Custom Search