How can I rethrow an Inner Exception while maintaining the stack trace generated so far?

后端 未结 8 1928
春和景丽
春和景丽 2021-01-31 05:03

Duplicate of: In C#, how can I rethrow InnerException without losing stack trace?

I have some operations that I invoke asynchronously on a background thread. Sometimes,

8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-31 05:53

    As others have said, use the "throw" keyword without adding to it to keep the exception chain intact. If you need that original exception (assuming that is what you mean) then you could call Exception.GetBaseException() at the end of your chain to get the Exception that started it all.

提交回复
热议问题