In Java bytecode, there is an option to specify the constant pool index 0 as the exception handler type, allowing you to catch all exceptions. However, as I understand it, this is exactly identical to catching Throwable. So what is the purpose of this feature? Did the designers of Java one day envision adding types of exceptions that don’t inherit from Throwable? It doesn’t look like it, but I can’t think of another explanation apart from laziness.
Share
The JVM specification (§4.7.3) states:
Although the use of catch_type zero is not specifically discussed in §3.13, the hint that it is used when compiling
finallyclauses in Java gives a clue. It may be that the JVM designers wanted a simple way to refer to all exception types without having to specifically refer to theThrowableclass. The use of catch_type zero would be easier for the JVM to identify rather than having to index into the constant pool and resolve thejava/lang/Throwableclass name there.In practical terms, as you say a catch_type zero or an index into the constant pool referring to
java/lang/Throwableshould work identically.