DEVFYI - Developer Resource - FYI

Does the code in finally block get executed if there is an exception and a return statement in a catch block?

Java Interview Questions and Answers (part 1)


(Continued from previous question...)

118. Does the code in finally block get executed if there is an exception and a return statement in a catch block?

If an exception occurs and there is a return statement in catch block, the finally block is still executed. The finally block will not be executed when the System.exit(1) statement is executed earlier or the system shut down earlier or the memory is used up earlier before the thread goes to finally block.

(Continued on next question...)

Other Interview Questions