Java Reference
In-Depth Information
the asynchronous exception that is thrown is an instance of a subclass of
Virtu-
alMethodError
.
Note that
StackOverflowError
, a subclass of
VirtualMethodError
, may be thrown
synchronously by method invocation (§
15.12.4.5
) as well as asynchronously
due to
native
method execution or Java Virtual Machine resource limitations.
Similarly,
OutOfMemoryError
, another subclass of
VirtualMethodError
, may be
as asynchronously.
The Java SE platform permits a small but bounded amount of execution to occur before an
asynchronous exception is thrown.
Asynchronous exceptions are rare, but proper understanding of their semantics is ne-
cessary if high-quality machine code is to be generated.
The delay noted above is permitted to allow optimized code to detect and throw these
exceptions at points where it is practical to handle them while obeying the semantics
of the Java programming language. A simple implementation might poll for asyn-
chronous exceptions at the point of each control transfer instruction. Since a program
has a finite size, this provides a bound on the total delay in detecting an asynchronous
exception. Since no asynchronous exception will occur between control transfers, the
code generator has some flexibility to reorder computation between control transfers
for greater performance. The paper
Polling Efficiently on Stock Hardware
by Marc
Feeley,
Proc. 1993 Conference on Functional Programming and Computer Architec-
ture
, Copenhagen, Denmark, pp. 179-187, is recommended as further reading.
11.2. Compile-Time Checking of Exceptions
The Java programming language requires that a program contains handlers for
checked ex-
ceptions
which can result from execution of a method or constructor. For each checked ex-
This compile-time checking for the presence of exception handlers is designed to reduce
the number of exceptions which are not properly handled. The checked exception classes
user of the method or constructor. The
throws
clause of an overriding method may not spe-
cify that this method will result in throwing any checked exception which the overridden