Java Reference
In-Depth Information
The program will generate an ArithmeticException when the division by zero is attemp-
ted. It will generate an ArrayIndexOutOfBoundsException when the attempt is made to
access outside the bounds of chrs . Both exceptions are caught by the single catch state-
ment.
The more precise rethrow feature restricts the type of exceptions that can be rethrown to
only those checked exceptions that the associated try block throws, that are not handled by
a preceding catch clause, and that are a subtype or supertype of the parameter. While this
capability might not be needed often, it is now available for use. For the final rethrow fea-
ture to be in force, the catch parameter must be effectively final . This means that it must
not be assigned a new value inside the catch block. It can also be explicitly specified as
final , but this is not necessary.
Java's Built-in Exceptions
Inside the standard package java.lang , Java defines several exception classes. A few have
been used by the preceding examples. The most general of these exceptions are subclasses
of the standard type RuntimeException . Since java.lang is implicitly imported into all
Search WWH ::




Custom Search