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
thrown synchronously during object creation (§ 12.5 ), array creation (§ 15.10.1 ,
§ 10.6 ) , class initialization (§ 12.4.2 ), and boxing conversion (§ 5.1.7 ), as well
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-
ception which is a possible result, the throws clause for the method (§ 8.4.6 ) or constructor
8.8.5 ) must mention the class of that exception or one of the superclasses of the class of
that exception (§ 11.2.3 ) .
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
11.1.1 ) named in the throws clause are part of the contract between the implementor and
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
method is not permitted, by its throws clause, to throw (§ 8.4.8.3 ) .
Search WWH ::




Custom Search