Possible Duplicate:
Is there such case when in try\finally block the finally won't be executed?
is there any code, that will never execute finally clause?
Java Tutorials
Not only for System.exit , but also for thread interrupted
Note: If the JVM exits while the try or catch code is being executed, then the finally block will not execute. Likewise, if the thread executing the try or catch code is interrupted or killed, the finally block will not execute even though the application as a whole continues.
System.exit(0)
is one example. If you compile and run below "Bye" will never get printed.
public class Main {
public static void main(String[] args) {
try {
System.out.println("Hi");
System.exit(0);
}
finally {
System.out.println("Bye!");
}
}
}
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