try {
if (check) {
while (true) ;
} else {
System.exit(1);
}
} finally {
clear();
}
Q: Is there a case where clear() never gets executed?
I personally feel that there are no cases where clear() will not be executed.
If System.exit succeeds, the clear() will not be executed. However, System.exit(1) could throw SecurityException exception, in which case clear() will be executed.
If check is true, then you are stuck in an infinite loop, in which case you never technically get to the finally block.
Else if check is false, then System.exit(1); is executed and your program terminates; in which case it never gets to the finally block to execute clear().
In this example, it is actually not possible to reach clear()
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