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/catch regardless if the try or the catch returned normally or exceptionally.
A System.exit however prevents the block from returning at all.
(As Peter points out however, while(true) ; will obviously block indefinitely. A just assumed that the while (true) ; was a stub for something that made more sense :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With