Exception handling | Sololearn: Learn to code for FREE!


Exception handling

Why is it that if a try block doesn't have any exception then my try block is executed first and then my finally block. But if I have an exception in my try block then my finally block executes first and then the exception message is shown.

11/21/2019 10:45:58 AM


2 Answers

New Answer


That is because exception transfers the flow of code to the place where it is handled (never to return again) or not, so finally block needs to be executed to free up resources or whatever you want to do before the transfer of code flow. When there is no exception the statements are simply executed normally.


~ swim ~ Thank you, got it.