+ 7
Java Question Problem đŽ
What will happen if we put System.exit(0) on try or catch body? Will finally block executed or any new exception will generate????
2 Answers
+ 3
@Nithiwat that means when we call system.exit() method in try catch body then finally block will not execute đŽ btw one of my friend is saying that if we call system.exit() which is written in try or catch block then then a new exception will generate and because of that finally block will executed
+ 24
The only times finally won't be called are:
1. If you invoke System.exit();
2. If the JVM crashes first;
3. If there is an infinite loop (or some other non-interruptable, non-terminating statement) in the try block;
4. If the OS forcibly terminates the JVM process; e.g. "kill -9 " on UNIX.
5. If the host system dies; e.g. power failure, hardware error, OS panic, etcetera.
https://stackoverflow.com/questions/65035/does-finally-always-execute-in-java