131.

prev next contents
athrow

throw an exception

Jasmin Syntax
     athrow 
Stack

Before

After
objectref
n/a
...

Description

Removes objectref (a reference to an object) from the operand stack, and 'throws' the exception represented by that object. objectref is an instance of Throwable or one of its subclasses.

To throw an exception, the system searches for a handler for objectref's class in the exception table of the currently active method.

If no handler is found, the current method's frame is discarded, its invoker's frame is reinstated, and the exception is immediately rethrown. This process is repeated until a handler is found or until there are no more procedures on the callstack (at which point, the current thread dies, typically printing out an error message).

If a handler is found, the operand stack of the active method is cleared, objectref is pushed on the operand stack of the current method, and execution continues at the first instruction of the handler.

See Chapter 10 for a full description of exceptions in the JVM.

Example

 ; Throw an IOException. This is equivalent to the Java code: ; ;   throw new java.io.IOException(); ; new java/io/IOException          ; 1) create and initialize an IOException instance dup                                      invokespecial java/io/IOException/<init>()V  athrow                           ; 2) throw the IOException instance on the stack 
Exceptions

NullPointerException - the objectref on the stack is null.

Bytecode

Type

Description
u1
athrow opcode = 0xBF (191)


prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine
Java Virtual Machine (Java Series)
ISBN: 1565921941
EAN: 2147483647
Year: 1996
Pages: 171

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net