11.4
An Example of Exceptions
EXCEPTIONS
Asynchronous exceptions are rare in Java. They occur only as a result of:
An invocation of the
stop
methods of class
Thread
( 20.20.15, 20.20.16) or
ThreadGroup
( 20.21.8, 20.21.9)
An
InternalError
( 11.5.2.2) in the Java Virtual Machine
The
stop
methods may be invoked by one thread to affect another thread or all the
threads in a specified thread group. They are asynchronous because they may
occur at any point in the execution of the other thread or threads. An
InternalError
is considered asynchronous so that it may be handled using the
same mechanism that handles the
stop
method, as will now be described.
Java permits a small but bounded amount of execution to occur before an
asynchronous exception is thrown. This delay 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 language.
A simple implementation might poll for asynchronous exceptions at the point
of each control transfer instruction. Since a Java 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 genera
tor has some flexibility to reorder computation between control transfers for
greater performance.
The paper
Polling Efficiently on Stock Hardware
by Mark Feeley,
Proc. 1993
Conference on Functional Programming and Computer Architecture
, Copen
hagen, Denmark, pp. 179 187, is recommended as further reading.
Like all exceptions, asynchronous exceptions are precise ( 11.3.1).
11.4 An Example of Exceptions
Consider the following example:
class TestException extends Exception {
TestException() { super(); }
TestException(String s) { super(s); }
}
class Test {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
206
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved