11.1
The Causes of Exceptions
EXCEPTIONS
rent thread. This process continues until a handler is found that indicates that it
handles that particular exception by naming the class of the exception or a super
class of the class of the exception. If no such handler is found, then the method
uncaughtException
( 20.21.31) is invoked for the
ThreadGroup
that is the par
ent of the current thread thus every effort is made to avoid letting an exception
go unhandled.
The Java exception mechanism is integrated with the Java synchronization
model ( 17), so that locks are released as
synchronized
statements ( 14.17) and
invocations of
synchronized
methods ( 8.4.3.5, 15.11) complete abruptly.
This chapter describes the different causes of exceptions ( 11.1). It details
how exceptions are checked at compile time ( 11.2) and processed at run time
( 11.3). A detailed example ( 11.4) is then followed by an explanation of the
exception hierarchy and the standard exception classes ( 11.5).
11.1 The Causes of Exceptions
If we do not succeed, then we run the risk of failure.
J. Danforth Quayle (1990)
An exception is thrown for one of three
reasons
:
An abnormal execution condition was synchronously detected by a Java Vir
tual Machine. Such conditions arise because:
N
evaluation of an expression violates the normal semantics of the Java lan
guage, such as an integer divide by zero, as summarized in 15.5
N
an error occurs in loading or linking part of the Java program ( 12.2, 12.3)
N
some limitation a resource is exceeded, such as using too much memory
These exceptions are not thrown at an arbitrary point in the program, but
rather at a point where they are specified as a possible result of an expression
evaluation or statement execution.
A
throw
statement ( 14.16) was executed in Java code.
An asynchronous exception occurred either because:
N
the method
stop
of class
Thread
( 20.20.16) was invoked
N
an internal error has occurred in the virtual machine ( 11.5.2.2)
Exceptions are represented by instances of the class
Throwable
and instances
of its subclasses. These classes are, collectively, the
exception classes
.
202
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved