try {
if (myBoolean) {
while (true) ;
} else {
System.exit(1);
}
} finally {
code.to.cleanup();
}
I am not entirely sure, but here’s the above code snippet that i feel may cause the finally clause to not execute, regardless of myBoolean’s value
No,
System.exit(1)prevents the finally clause from running.Basically a finally block is executed after a
try/catchregardless if thetryor thecatchreturned normally or exceptionally.A
System.exithowever prevents the block from returning at all.(As Peter points out however,
while(true) ;will obviously block indefinitely. A just assumed that thewhile (true) ;was a stub for something that made more sense 🙂