Java Reference
In-Depth Information
An implicitly final exception parameter is final by virtue of its declaration, while an
effectively final exception parameter is (as it were) final by virtue of how it is used.
An exception parameter of a multi- catch clause is implicitly final, so will never occur
as the left-hand operand of an assignment operator, but it is not considered effectively
final.
If an exception parameter is effectively final (in a uni- catch clause) or implicitly final
(in a multi- catch clause), then adding an explicit final modifier to its declaration will not
introduce any compile-time errors. However, if the exception parameter of a uni- catch
clause is explicitly declared final , then removing the final modifier may introduce
compile-time errors. This is because the exception parameter, while still effectively
final, can no longer be referenced by, for example, local classes. On the other hand, if
there are no compile-time errors, it is possible to further change the program so that
the exception parameter is re-assigned and no longer effectively final.
The exception types that a try statement can throw are specified in § 11.2.2 .
The relationship of the exceptions thrown by the try block of a try statement and caught by
the catch clauses (if any) of the try statement is specified in § 11.2.3 .
Exception handlers are considered in left-to-right order: the earliest possible catch clause
accepts the exception, receiving as its argument the thrown exception object, as specified
in § 11.3 .
A multi- catch clause can be thought of as a sequence of uni- catch clauses. That is, a
catch clause whose exception parameter type is denoted as a union D 1 | D 2 | ... | D n is equi-
valent to a sequence of n catch clauses whose exception parameters have class types
D 1 , D 2 , ..., D n , respectively. For example, the following code:
Click here to view code image
try {
... throws ReflectiveOperationException ...
}
catch (ClassNotFoundException | IllegalAccessException ex) {
... body ...
}
is semantically equivalent to the following code:
Click here to view code image
try {
... throws ReflectiveOperationException ...
} catch (final ClassNotFoundException ex1) {
Search WWH ::




Custom Search