+ 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????

20th Jan 2018, 1:04 PM
ŠÆ. ā™Ø
ŠÆ. ā™Ø - avatar
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
20th Jan 2018, 2:25 PM
ŠÆ. ā™Ø
ŠÆ. ā™Ø - avatar
+ 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
20th Jan 2018, 1:37 PM
Nithiwat
Nithiwat - avatar