Running code on program exit in Java [duplicate]
Use Runtime.getRuntime().addShutdownHook(Thread).
Use Runtime.getRuntime().addShutdownHook(Thread).
No. System.exit(0) doesn’t return, and the finally block is not executed. System.exit(int) can throw a SecurityException. If that happens, the finally block will be executed. And since the same principal is calling the same method from the same code base, another SecurityException is likely to be thrown from the second call. Here’s an example of … Read more
The parameter of exit should qualify if the execution of the program went good or bad. It’s a sort of heredity from older programming languages where it’s useful to know if something went wrong and what went wrong. Exit code is 0 when execution went fine; 1, -1, whatever != 0 when some error occurred, … Read more