开发者

Testing for stack unwinding during statement execution

Is there a way in C# to test whether the execution of a statement happens during exception stack unwinding or not?

Thanks, Marcello.

Edit: I mean something like this:

using (NewDbTransact开发者_如何学Goion()) { 
  //do some DB stuff here
} <-- here Dispose() of IDisposable is called 

void DbTransactionWrapper.Dispose() { 
  if (InException()) //is this possible???
    Rollback();
  else
    Commit();
}


Simply catch and rethrow the exception.

Edit: Or did you mean "how do I detect an exception in the finally block"? In that case You could just set a flag in the catch block and read it in the finally block.


The stacktrace class may give you some help here, but you'd have to do a fair bit of work yourself examining the stack. I don't think there's an easy way to spot that the code is called from an exception block.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜