I never properly understood the use of the finally statement. Can anyone tell me what the difference is between: on the one hand and: On the other Answer They differ if the try-block completes by throwing a java.lang.Throwable that is not a java.lang.Exception, for instance because it is a java.lang.Error such as AssertionError or OutOfMemoryError. the try-block completes abruptly using
Tag: try-catch-finally
Does a finally block always get executed in Java?
Considering this code, can I be absolutely sure that the finally block always executes, no matter what something() is? Answer Yes, finally will be called after the execution of the try or catch code blocks. The only times finally won’t be called are: If you invoke System.exit() If you invoke Runtime.getRuntime().halt(exitStatus) If the JVM crashes first If the JVM reaches