c# - Will finally run after return? -


this question has answer here:

i have block of code:

try{     this.connection.open();     cmd.executescalar();     return true; } catch(exception exc){     throw exc; } finally{     this.connection.close(); } 

i know if catch throws exception, finally block run anyways.

but return in try?

if try block returns true, finally block close connection?

is safe?

yes, does. safe work now.

it executes finally after exit code block, no matter if caused return or not.


Comments