0

Possible Duplicate:
Does a finally block always run?

let's imagine the following scenario:

public void myMethod() throws MyException
  try
  {
     // do something
     // an Exception (for example an individual written MyException which extends 
     // "Exception" is thrown here
  }
  catch (OtherException e)
  {
    // do something
  }
  finally 
  {
    // do something else
  }
}

In case "MyException" is thrown in the try block and would not be catched - they finally block would be reached nonetheless, correct?

What if it would be an Runtime Exception, which would be thrown? Would the finally block be reached?

Is there any case where a finally block won't be reached?

Thanks for an answer :-)

Community
  • 1
  • 1
nano7
  • 2,455
  • 7
  • 35
  • 52

1 Answers1

6

Finally is always called unless you have a vm crash or call System.exit.

Steven
  • 3,844
  • 3
  • 32
  • 53