Java Reference
In-Depth Information
One group of subclasses of Exception that are exempted from this are those derived from
RuntimeException . The reason that RuntimeException exceptions are treated differently, and
that the compiler allows you to ignore them, is that they generally arise because of serious errors in your
code. In most situations there is little you can do to recover the situation. However, in some contexts for
some of these exceptions, this is not always the case, and you may well want to include code to
recognize them. There are quite a lot of subclasses of RuntimeException that are used to signal
problems in various packages in the Java class library. Let's look at the exception classes that have
RuntimeException as a base that are defined in the java.lang package.
The subclasses of RuntimeException defined in the standard package java.lang are:
Class Name
Exception Condition Represented
ArithmeticException
An invalid arithmetic condition has arisen such as an
attempt to divide an integer value by zero.
IndexOutOfBoundsException
You've attempted to use an index that is outside the
bounds of the object it is applied to. This may be an
array, a String object, or a Vector object. The class
Vector is defined in the standard package,
java.util . We will be looking into the Vector class
in Chapter 13.
NegativeArraySizeException
You tried to define an array with a negative dimension.
NullPointerException
You used an object variable containing null , when it
should refer to an object for proper operation - for
example, calling a method or accessing a data member.
ArrayStoreException
You've attempted to store an object in an array that
isn't permitted for the array type.
ClassCastException
You've tried to cast an object to an invalid type - the
object isn't of the class specified, nor is it a subclass, or
a superclass, of the class specified.
IllegalArgumentException
You've passed an argument to a method which doesn't
correspond with the parameter type.
SecurityException
Your program has performed an illegal operation that
is a security violation. This might be trying to read a
file on the local machine from an applet.
IllegalMonitor
StateException
A thread has tried to wait on the monitor for an object
that the thread doesn't own. (We'll look into threads in
Chapter 15).
IllegalStateException
You tried to call a method at a time when it was not
legal to do so.
Unsupported
OperationException
Thrown if you request an operation to be carried out
that is not supported.
Search WWH ::




Custom Search