Good answers can be found here.
Besides a System.exit()
, the finally block will not run if the JVM crashes for some reason (e.g. infinite loop in your try
block).
As far as the thread itself, only if it is stopped using the stop()
method (or suspend()
without resume()
) will the finally
block not be executed. A call to interrupt()
will still result in the finally
block being executed.
It's also worth noting that, since any return
statement in the finally
block will override any returns or exception throws in the try
/catch
blocks, program behavior can quickly become erratic and hard to debug if this happens to you. Not really anything worth taking precaution against (as it only happens in extremely rare cases), but worth being aware of so you can recognize it when it happens.