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

后端 未结 8 2066
春和景丽
春和景丽 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:52

    Using the "throw" keyword with an exception will always reset the stack trace.

    The best thing to do is to catch the actual exception you want, and use "throw;" instead of "throw ex;". Or to throw your own exception, with the InnerException that you want to pass along.

    I don't believe what you want to do is possible.

提交回复
热议问题