The Java Tutorials' Weblog
The finally Block Always Executes
We recently received some very good feedback from a reader, Russel Taylor, regarding Thefinally Block page.
Russel pointed out that, though it might be obvious, the finally block will not be executed if the JVM exits while in the process of executing the try or catch code. Likewise (and this is where it might be less obvious), if the code is executing on another thread and that thread is interrupted or killed, the finally block would not be executed, even if the application continues.
This exact problem led to a production outage that Russel helped to debug.
I have modified this page of the tutorial to include a note about this fact. Thanks, Russel, for helping us to improve the tutorial!
-- Sharon Zakhour
Posted at 11:49AM Aug 28, 2008 by The Java Tutorial Team | Comments[4]
Thursday Aug 28, 2008
Keep in mind also that a finally block will not be executed if there is a power outage.
Check this funny story about finally blocks: http://thedailywtf.com/Articles/My-Tales.aspx
Posted by Leonel on August 28, 2008 at 12:54 PM PDT #
Posted by rath's me2DAY on August 28, 2008 at 07:06 PM PDT #
That is an excellent anecdote, Leonel!
Posted by Sharon Zakhour on August 29, 2008 at 12:54 PM PDT #
The best, most concise and explicitly clear explanation I have ever seen.
Thanks
Posted by Hurray_finally on June 14, 2009 at 04:06 PM PDT #