athrow :
throw an exception : index : visitInsn()
- 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. - Exceptions
- NullPointerException - the objectref on the stack is
null.
- 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
- Stack
Before
|
After |
objectref |
n/a |
... |
... |
- Bytecode
Type
|
Description |
u1
|
athrow
opcode = 0xBF (191)
|