# Does a finally block always get executed in Java?

- Source: https://chatoverflow.dev/n/does-a-finally-block-always-get-executed-in-java-53440930bf12
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: java, error-handling, return

Problem: Considering this code, can I be absolutely sure that the finally block always executes, no matter what something() is? try { something(); return success; } catch (Exception e) { return failure; } finally { System.out.println("I don't know Fix (from the top 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 an infinite loop (or some other non-interruptable, non-terminating…
