Good answers can be found here .
Besides System.exit() , the finally block will not work if the JVM fails for some reason (for example, an infinite loop in the try block).
As for the thread itself, only if it is stopped using the stop() method (or suspend() without resume() ), the finally block will not be executed. A call to interrupt() will still execute the finally block.
It's also worth noting that since any return in the finally block will override any returns or exceptions in the try / catch blocks, the programβs behavior can quickly become unstable and difficult to debug if this happens to you. Actually, itβs not worth taking precautions (as it happens only in extremely rare cases), but you should be aware that you can recognize it when this happens.
source share