Java Reference
In-Depth Information
• The expression is a qualified class instance creation expression and the qualifying
expression can throw
E
; or
• Some expression of the argument list can throw
E
; or
•
E
is determined to be an exception class of the
throws
clause of the constructor that
is invoked (§
15.12.2.6
); or
• The class instance creation expression includes a
ClassBody
, and some instance
initializer block or instance variable initializer expression in the
ClassBody
can
throw
E
.
A method invocation expression (§
15.12
) can throw an exception class
E
iff either:
• The method to be invoked is of the form
Primary.Identifier
and the
Primary
ex-
pression can throw
E
; or
• Some expression of the argument list can throw
E
; or
•
E
is determined to be an exception class of the
throws
clause of the method that is
invoked (§
15.12.2.6
).
For every other kind of expression, the expression can throw an exception class
E
iff one
of its immediate subexpressions can throw
E
.
11.2.2. Exception Analysis of Statements
effectively final exception parameter can throw
E
or any exception class that the thrown
expression can throw.
For example, the statement
throw new java.io.FileNotFoundException();
can throw
java.io.FileNotFoundException
only. Formally, it is not the case that it “can throw” a sub-
class or superclass of
java.io.FileNotFoundException
.
A
throw
statement whose thrown expression is a final or effectively final exception para-
meter of a
catch
clause
C
can throw an exception class
E
iff:
•
E
is an exception class that the
try
block of the
try
statement which declares
C
can
throw; and
•
E
is assignment compatible with any of
C
's catchable exception classes; and
•
E
is not assignment compatible with any of the catchable exception classes of the
catch
clauses declared to the left of
C
in the same
try
statement.