I had a rather painful troubleshooting experience finding and fixing some errors that looked like this:
try { doSomeStuff() doMore() } finally { doSomeOtherStuff() }
The problem was difficult to troubleshoot because doSomeStuff () threw an exception, which in turn threw doSomeOtherStuff () to throw an exception as well. The second exception (thrown by the finally block) was passed to my code, but it did not have the handle of the first exception (selected from doSomeStuff ()), which was the main cause of the problem.
If this code said this, the problem would be obvious:
try { doSomeStuff() doMore() } catch (Exception e) { log.error(e); } finally { doSomeOtherStuff() }
So my question is this:
Is the finally block used by a non-blocking catch java anti-pattern known? (This, of course, does not seem to be a completely understandable subclass of the obviously well-known anti-pattern "Don't catch exceptions!")
java c ++ c # exception try-catch-finally
Jared Mar 02 '09 at 3:08 2009-03-02 03:08
source share