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
Post a Comment