Java Reference
In-Depth Information
• If within a constructor or an instance initializer or the initializer for an instance
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
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
The control transfer that occurs when an exception is thrown causes abrupt completion
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.