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
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
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
The
catchable exception classes
of a multi-
catch
clause are the alternatives in the union that
11.2.1. Exception Analysis of Expressions