Is there possibility that a finally block might not execute?

If the JVM exits while the try or catch code is being executed, then the finally block may not execute. Likewise, if the thread executing the try or catch code is interrupted or killed, the finally 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.

Tags:

Java

Exception