Java Reference
In-Depth Information
It can be seen, then, that a
return
statement always completes abruptly.
The preceding descriptions say “attempts to transfer control” rather than just “trans-
structor whose
try
blocks or
catch
clauses contain the
return
statement, then any
finally
clauses of those
try
statements will be executed, in order, innermost to outermost, be-
fore control is transferred to the invoker of the method or constructor. Abrupt comple-
tion of a
finally
clause can disrupt the transfer of control initiated by a
return
statement.
14.18. The
throw
Statement
A
throw
statement causes an exception (§11) to be thrown. The result is an immediate trans-
initializer, static initializer and field initializer evaluations, and method invocations until
invocation of the
uncaughtException
method for the thread group to which the thread belongs.
ThrowStatement:
throw
Expression
;
The
Expression
in a
throw
statement must denote either 1) a variable or value of a reference
time error occurs.
The reference type of the
Expression
will always be a class type (since no interface
types are assignable to
Throwable
) which is not parameterized (since a subclass of
At least one of the following three conditions must be true, or a compile-time error occurs:
type (§
4.1
).
not the case that the
try
statement can throw an exception of the type of the
Expres-
sion
. (In this case we say the thrown value is
caught
by the
try
statement.)
• The
throw
statement is contained in a method or constructor declaration and the
type of the
Expression
is assignable (§
5.2
) to at least one type listed in the
throws