0

Java – how to not execute the finally clause

They say that when an Exception occurs, the finally clause, if available, always executes no matter what except for one thing.

The statement at line 11 will always execute whether or not Exception occurred. The codes will output the following.

Skip Finally

This statement will skip the finally clause and terminate the whole JVM.

If we put this statement in the catch clause just after the e.printStackTrace();, we will not see the word “Finally!” displayed.

This outputs only this