Java Reference
In-Depth Information
4. The exception handler takes action and ends the exception response.
Bullt-in exception handling
Programming languages differ widely in the level of built-in support for
handling exceptions. Some languages provide no exception handling aid,
while others contain sophisticated mechanisms to support error response
and to ensure that all exceptions are adequately handled.
When languages like Java contain built-in exception handlers, there
are various implementation issues and design issues that must be consid-
ered. For example:
1. Does the language's runtime environment provide default action for some
or all exceptions?
2. Can user code raise exceptions?
3. Are hardware-detectable errors treated as exceptions?
4. Can the language's exception mechanism be temporarily or permanently
disabled?
5. Where does execution continue after an exception response concludes?
PL/I was the first major language to provide exception handling. The
PL/I exception handling facilities are powerful and flexible; however,
most language designers consider them too complex. The most of-
ten-mentioned problem is that exceptions are bound dynamically to the
handlers. A more reasonable model provides for statically bound excep-
tion handlers. The statically bound handlers were adopted in the Ada lan-
guage, which also includes a mechanism for propagating unhandled
exceptions to some other program unit.
Java's approach
Java's approach to exceptions is based on the model proposed in the 1990
ANSI standardization committee for C++. This model, in turn, is based on
the one used in the research language ML (Meta Language) developed at
Bell Labs. The resulting approach to exception handling has been imple-
mented in most modern versions of the C++ compiler, as well as in Java.
Java exception handling is based on three basic constructs, named
throw , try , and catch . The throw keyword is used to raise or re-raise an
exception. The try and catch blocks implement the exception handler. An
additional optional block, named finally , is used within exception han-
dlers to provide an alternate processing option.
Search WWH ::




Custom Search