2

Considering the below code, does finally still run if there was an exception thrown in the catch clause?

try {
//code here throws exception
}
catch(Exception ex) {
//code catches above exception however code here also throws another exception
}
finally {
//does this code even run considering the exception thrown in the above catch clause??
}
dido
  • 3,347
  • 11
  • 34
  • 42
  • possible duplicate of [What is the difference between finally and no finally?](http://stackoverflow.com/questions/5834175/what-is-the-difference-between-finally-and-no-finally) – andersoj Apr 25 '12 at 01:30
  • 1
    It seems to me you could replace the comments in your question with a line or two of code and test this yourself. You'd get an answer much faster, and might learn a thing or two extra in the process. :) – Ken White Apr 25 '12 at 01:33
  • Yes, duplicate of and answered excellently by [this answer](http://stackoverflow.com/a/5834290/712765) to "What is the difference between finally and no finally?" – Old Pro Apr 25 '12 at 01:41

1 Answers1

7

Yes it does. It runs regardless of what happens in the try/catch (assuming the JVM doesn't shut down for some reason)

Aidanc
  • 6,921
  • 1
  • 26
  • 30