Penske Truck Leasing interview question

Will a Java program reach the finally block if you return from the try block?

Interview Answers

Anonymous

13 Mar 2015

If finally wasn't called then it would be more apt to call the keyword 'perhaps' The only conditions for which it wouldn't be called are if the JVM crashes or if you call System.exit

Anonymous

1 Jul 2013

Yes, the code in the finally block will still be executed. I guessed on this one as this isn't a scenario commonly seen in code (should be avoided, frankly) and I honestly couldn't remember. These are the kind of 'gotcha' textbook questions that test someone's memory more than their programming ability and should not be included in a professional interview.