Joel Christophel wrote:
Stephan van Hulst wrote:Code inside the finally block is *always* executed
Unless System.exit() is executed in either the try or catch block.
... or System.exit() is called in another
thread, or this try/finally is in a daemon thread and all the non-daemon threads complete, or the JVM dumps core, or someone pulls the plug, or a meteor destroys the earth, or...
There are an infinity of scenarios in which it won't run, so just enumerating one of them opens the door to a can of incompletion and confusion-shaped worms.
A more precise and cover-all-the-bases way to put it would be something like, "As long as the thread continues executing, finally is guaranteed to execute after the try and a catch block if one was invoked, before transferring control to the next statement or back up the stack to the calling method."