athrow 0xbf

Throws the exception on top of the stack.

Opcode
0xbf (191)
Family
Objects and types
Operands
none
Length
1 byte
Operand stack
…, objectref → …, objectref
Can throw
NullPointerException, IllegalMonitorStateException

What it does

Throws the exception on top of the stack. The JVM looks for a handler covering this instruction in the method's exception table; if there is none, the frame is popped and the search continues in the caller. Throwing null throws a NullPointerException instead.

javac emits it for throw, and at the end of every finally block's exception path, to rethrow what was caught.

How often javac uses it

In JDK 25.0.5's java.base module, athrow appears 16,191 times in 2,698 of its 7,391 classes: 0.83% of all instructions, the 34th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.getInIfOpen, java.io.BufferedOutputStream.<init>, java.io.BufferedReader.<init>, java.io.BufferedReader$1.hasNext.

Examples

From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; athrow is highlighted.

static String cast(Object o) in Tour, compiled by javac 25
96if (o == null) throw new IllegalArgumentException("null");
0aload_0 // o
4new #57// IllegalArgumentException
7dup
8ldc #59// "null"
10invokespecial #61// new IllegalArgumentException(String)
97if (!(o instanceof CharSequence)) return null;
14aload_0 // o
15instanceof #64// CharSequence
98return (String) o;
23aload_0 // o
24checkcast #16// String

Open in the viewer

static int half(int n) in Asserts, compiled by javac 25
4assert n % 2 == 0 : "odd: " + n;
0getstatic #7// Asserts.$assertionsDisabled : boolean
6iload_0 // n
12new #13// AssertionError
15dup
16iload_0 // n
17invokedynamic #15// makeConcatWithConstants(int) : String ⇐ StringConcatFactory.makeConcatWithConstants "odd: \1"
22invokespecial #19// new AssertionError(Object)
5return n / 2;
26iload_0 // n
28idiv

Open in the viewer

Related instructions

new Allocates an object (uninitialised until its constructor runs).monitorexit Pops an object and unlocks its monitor.return Returns from a void method.

Specification: JVMS §6.5, athrow (Java SE 25).