Java Reference
In-Depth Information
When interfaces are involved, more than one method declaration may be overridden by
a single overriding declaration. In this case, the overriding declaration must have a throws
clause that is compatible with all the overridden declarations (§ 9.4.1 ) .
The unchecked exception classes (§ 11.1.1 ) are exempted from compile-time checking.
Of the unchecked exception classes, error classes are exempted because they can oc-
cur at many points in the program and recovery from them is difficult or impossible.
A program declaring such exceptions would be cluttered, pointlessly. Sophisticated
programs may yet wish to catch and attempt to recover from some of these conditions.
Of the unchecked exception classes, run-time exception classes are exempted be-
cause, in the judgment of the designers of the Java programming language, having to
declare such exceptions would not aid significantly in establishing the correctness of
programs. Many of the operations and constructs of the Java programming language
can result in exceptions at run time. The information available to a Java compiler, and
the level of analysis a compiler performs, are usually not sufficient to establish that
such run-time exceptions cannot occur, even though this may be obvious to the pro-
grammer. Requiring such exception classes to be declared would simply be an irrita-
tion to programmers.
For example, certain code might implement a circular data structure that, by construc-
tion, can never involve null references; the programmer can then be certain that a
NullPointerException cannot occur, but it would be difficult for a Java compiler to prove
it. The theorem-proving technology that is needed to establish such global properties
of data structures is beyond the scope of this specification.
We say that a statement or expression can throw a checked exception class E if, according
to the rules in § 11.2.1 and § 11.2.2 , the execution of the statement or expression can result
in an exception of class E being thrown.
We say that a catch clause can catch its catchable exception class(es).
The catchable exception class of a uni- catch clause is the declared type of its exception
parameter (§ 14.20 ) .
The catchable exception classes of a multi- catch clause are the alternatives in the union that
denotes the type of its exception parameter (§ 14.20 ) .
11.2.1. Exception Analysis of Expressions
A class instance creation expression (§ 15.9 ) can throw an exception class E iff either:
Search WWH ::




Custom Search