2 ms·
The JEP itself explains the reason why this limitation exists: > try { } Blocks > The restriction that super() and this() may not appear inside a try { } bloc
by tsimionescu 4y ago
The JEP itself explains the reason why this limitation exists:
> try { } Blocks
> The restriction that super() and this() may not appear inside a try { } block comes from the JVM itself, and is due to how StackMaps are represented. The logic is that when a superclass constructor throws an exception, the new instance on the stack is neither fully uninitialized nor fully initialized, so it should be considered unusable, and therefore such a constructor must never return. However, the JVM doesn't allow the bytecode to discard the unusable instance and throw another exception; instead, it doesn't allow it to exist on the stack at all. The net effect is that constructors can't catch exceptions thrown by superclass initialization, even if rethrown. [emphasis mine]