Avatar ·

Finally block always executes? JVM pitfalls and System.exit()

Hi everyone! I'm new to Java and trying to understand exception handling. I'm confused about the `finally` block. Textbooks say it always executes, regardless of whether an exception occurred or not. But I found several examples where this doesn't seem to be the case. For example, here's some code: ```java public class FinallyTest { public static void main(String[] args) { try { System.out.println("In try"); System.exit(0); } catch (Exception e) { System.out.println("In catch"); } finally { System.out.println("In finally"); } } } ``` I expected to see "In finally", but the program just terminated without this output. Why? `System.exit(0)` is not an exception, it's normal termination. And another one p