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

后端 未结 8 1926
春和景丽
春和景丽 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 06:02

    It is possible with .net 4.5:

    catch(Exception e)
    {
       ExceptionDispatchInfo.Capture(e.InnerException).Throw();
    }
    

提交回复
热议问题