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.)?
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