Is there possibility that a finally block might not execute?
If the JVM exits while the
try
orcatch
code is being executed, then thefinally
block may not execute. Likewise, if the thread executing thetry
orcatch
code is interrupted or killed, thefinally
block may not execute even though the application as a whole continues.
Source: java.sun.com: Java Tutorial: The finally Block
System.exit()
will prevent a finally
block from executing.
In the Java documentation:
http://java.sun.com/docs/books/tutorial/essential/exceptions/finally.html
It explains Finally very well.
They do note that if the JVM exits, that the finally block will not be called. Or if a thread that is running the block of code gets killed, the finally block will not be called. In all other cases it will.