I was checking into the oft repeated rumour that daemon threads on the JVM treat finally
blocks in some special way (they don't, ok?), when I read this, from the Oracle Java tutorial:
Note: 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.
(Emphasis is mine.) And the bit about interrupted caught my eye!
My belief is that if a thread is in try/catch code and is interrupted, then either we're in (or eventually enter) a state (eg sleep, wait) where we end up throwing an InterruptedException
, or we aren't and we drop out normally or abnormally, but in all cases we will hit the finally
clause.
What have I missed? Is there really a way for a Thread to be interrupted and then skip a finally
, whilst the application continues?