Java Reference
In-Depth Information
• If within a constructor or an instance initializer or the initializer for an instance
variable, then the caller is the class instance creation expression (§ 15.9 ) or the
method invocation of newInstance that was executed to cause an object to be created.
• If within a static initializer or an initializer for a static variable, then the caller is the
expression that used the class or interface so as to cause it to be initialized (§ 12.4 ) .
Whether a particular catch clause can handle an exception is determined by comparing the
class of the object that was thrown to the catchable exception classes of the catch clause.
The catch clause can handle the exception if one of its catchable exception classes is the
class of the exception or a superclass of the class of the exception.
Equivalently, a catch clause will catch any exception object that is an instanceof
15.20.2 ) one of its catchable exception classes.
The control transfer that occurs when an exception is thrown causes abrupt completion
of expressions (§ 15.6 ) and statements (§ 14.1 ) until a catch clause is encountered that can
handle the exception; execution then continues by executing the block of that catch clause.
The code that caused the exception is never resumed.
All exceptions (synchronous and asynchronous) are precise : when the transfer of control
takes place, all effects of the statements executed and expressions evaluated before the
point from which the exception is thrown must appear to have taken place. No expressions,
statements, or parts thereof that occur after the point from which the exception is thrown
may appear to have been evaluated.
If optimized code has speculatively executed some of the expressions or statements
which follow the point at which the exception occurs, such code must be prepared to
hide this speculative execution from the user-visible state of the program.
If no catch clause that can handle an exception can be found, then the current thread (the
thread that encountered the exception) is terminated. Before termination, all finally clauses
are executed and the uncaught exception is handled according to the following rules:
• If the current thread has an uncaught exception handler set, then that handler is ex-
ecuted.
• Otherwise, the method uncaughtException is invoked for the ThreadGroup that is the
parent of the current thread. If the ThreadGroup and its parent ThreadGroup s do not
override uncaughtException , then the default handler's uncaughtException method is in-
voked.
Search WWH ::




Custom Search