athrow


Operation Throw exception

athrow


or error

Forms athrow = 191 (0xbf)

Stack ..., objectref

objectref

Description The objectref must be of type reference and must refer to an object which is an instance of class Throwable or of a subclass of Throwable. It is popped from the operand stack. The objectref is then thrown by searching the current frame (§3.6) for the most recent catch clause that catches the class of objectref or one of its superclasses.

If a catch clause is found, it contains the location of the code intended to handle this exception. The pc register is reset to that location, the operand stack of the current frame is cleared, objectref is pushed back onto the operand stack, and execution continues. If no appropriate clause is found in the current frame, that frame is popped, the frame of its invoker is reinstated, and the objectref is rethrown.

If no catch clause is found that handles this exception, the current thread exits.

Runtime Exception If objectref is null, athrow throws a NullPointerException instead of objectref.


athrow

Notes The operand stack diagram for the athrow instruction may be misleading: If a handler for this exception is found in the current method, the athrow instruction discards all the words on the operand stack, then pushes the thrown object onto the stack. However, if no handler is found in the current method and the exception is thrown farther up the method invocation chain, then the operand stack of the method (if any) that handles the exception is cleared and objectref is pushed onto that empty operand stack. All intervening stack frames from the method that threw the exception up to, but not including, the method that handles the exception are discarded.