If the VM wanted to exit the program then it would just exit.
It has no need to use Exceptions to achieve that and, indeed, since we (the developers) can catch and handle exceptions then the VM has no guarantee that throwing an exception will actually result in the program exiting.

John Losty

Ranch Hand

Posts: 121

posted 1 week ago

But based on the exception(handled or not) the JVM will terminate or not?

Run the following code (on JShell or in a method):-Don't catch the exception. You will see that even though the “Main” Thread is terminated because of the uncaught exception, the frame remains visible showing the the Event Dispatch Thread (and therefore the JVM) is still running until you close the GUI.

John Losty

Ranch Hand

Posts: 121

posted 1 week ago

I am running this:

So that means that even thought exception terminated 1 thread(or did it?) it didnt terminate the JVM. So therefore it cannot be the mechanism to exit the program when something unexpected happens.?

But what is than the mechanism that the JVM uses to exit the program? System.exit() ?