Alex Rivera | Logout

Is `finally` block executed in case there is `return` inside a `try` or a `catch` block?

Asked 2011-10-19T02:52:14.353
19

Using a try-catch-finally construction to retrieve a database record, it seems that I need to return a value inside a try block in case everything was fine (as in case of an exception the end of the function is not meant to be reached). But If I return inside try, is finally code going to be reached (to close the connection etc.)?

Edit
Report

1 Answer

19

Yes,

The result of the try/catch expression will be the last line of either the try or catch block, but the finally block will always execute no matter what

answered 2011-10-19T02:59:59.463

Your Answer