First of all, the only idiom that can even be considered a candidate is this:
try {
Pay attention to the captured type. Only if you catch any possible exception, including such dark monsters as ThreadDeath and VirtualMachineError , can you hope to unconditionally reach the code below try-catch.
But this is only where it begins. What if the processing code itself throws an exception? So you need at least
try { } catch (Throwable t) { try { } catch (Throwable t) {
Now you can begin to understand the benefits of finally , but that’s not all. Consider a fairly typical scenario:
try { return true; } finally { }
How do you rewrite this? Without duplication of code is impossible.
Marko topolnik
source share