Based on the Java Virtual Machine Specification, exceptions are compiled as follows (in summary):
- try code is run normally
- each catch block is compiled as if it were a separate method
- there is an exception table to redirect the execution flow to the right catch block
When using a multi catch clause, the catch block is the same (appears only once), but the exception table will contain one more entry with the same from, to and target values.
For example, this code:
public static void main(String args[]) throws InterruptedException {
try {
System.out.println("why not?");
} catch (IllegalArgumentException e) {
System.out.println("here");
} catch (IllegalStateException | ArithmeticException e) {
System.out.println("there");
}
}
generates the following exception table (on my machine):
from to target type
0 8 11 Class java/lang/IllegalArgumentException
0 8 23 Class java/lang/IllegalStateException
0 8 23 Class java/lang/ArithmeticException