The code does not reach the "final" block
As stated in the Java 6 System.exit()
docs :
Calling is
System.exit(n)
actually equivalent to calling:Runtime.getRuntime().exit(n)
And if you go and see Runtime.exit()
(my bold):
Shuts down the current Java Virtual Machine by initiating its shutdown sequence. This method never returns normally.
The shutdown sequence for a virtual machine consists of two phases. In the first step, all registered stop hooks, if any, are triggered in a specific unspecified order and are allowed to start simultaneously until they finish. At the second stage, all uninitiated finalizers are run if the finalize on exit option is enabled. After that, the virtual machine stops.
Basically, the only function that this function can return (and therefore allow execution finally
) is that it raises SecurityException
, because any security manager works with a denied exit with a given code.
source to share
The method System.exit
stops the execution of the current thread and all other threads. Presence finally does not give the thread special permission to continue running.
The previous one discusses this in great detail. How does Java System.exit () work with try / catch / finally blocks?
source to share