c# - Is there a way to know if finally is executed after a try or a catch? -


i think title explain whole question.

i'd know, execute code on finally statement, if come try or catch.

is possible?

well, simplest approach is:

bool success = false; try {     ...     // should last statement in try block     success = true; } catch(...) {     ... } {     if (success)     {         ...     } } 

this isn't specific language feature - it's using fact other really remarkable situations (asynchronous exceptions, basically), you're not going exception occurring after assignment success.

note success being false doesn't mean of catch blocks have executed - exception thrown you're not catching (or returned before end of try block). only indicates "reached end of try block" - that's needed.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -