1

I just learned the lesson of Java Exception Handling. And I learned Java finally block is always executed whether exception is handled or not.

finally block

Is there any case when finally will not be executed?

Dhanuka
  • 2,826
  • 5
  • 27
  • 38
Hold.com
  • 19
  • 2

2 Answers2

1

finally block will not be executed if program exits; either by calling System.exit() or by causing a fatal error that causes the process to abort.

More information - https://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html

Dhanuka
  • 2,826
  • 5
  • 27
  • 38
0

The finally block is always called, except maybe if you do a System.exit().

Ridcully
  • 23,362
  • 7
  • 71
  • 86
  • 2
    This is a duplicate question and there are so many good answers in those original post. So you can vote for close question as duplicate. OP get more benefit from that. – Ruchira Gayan Ranaweera Apr 28 '15 at 05:31