Exceptions attribute
The checked exceptions a method declares.
- Appears on
- method
- Since
- class file 45.0 (Java 1.0)
- javac writes it
- for methods with a throws clause
- Needed by the JVM
- no: it is for the class libraries (reflection), compilers or tools
Layout
| Type | Field | What it holds |
|---|---|---|
u2 | attribute_name_index | a Utf8: "Exceptions" |
u4 | attribute_length | bytes after this field |
u2 | number_of_exceptions | |
u2[…] | exception_index_table | Class entries |
What it is for
The checked exceptions a method declares. The JVM ignores it: checked exceptions are purely a compiler rule, which is how other JVM languages, and sneaky-throw tricks, throw checked exceptions undeclared. Reflection reads it for getExceptionTypes().
How common it is
JDK 25.0.5's java.base has 8,427 Exceptions attributes, in 1,951 of its 7,391 classes (8,427 on methods).
A real one, byte by byte
From TryResources.class (compiled by javac 25), on method firstLine:
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 883 | 10 bytes | Exceptions | |
| 883 | 00 2e | attribute_name_index | #46 |
| 885 | 00 00 00 04 | attribute_length | 4 |
| 889 | 00 01 | number_of_exceptions | 1 |
| 891 | 00 2f | exception_index | #47 |
Specification: JVMS §4.7, The Exceptions Attribute (Java SE 25).