Skip to content

When exceptions are rethrown with throw ex;, the original context (the stack) is lost #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lefth opened this issue Apr 12, 2018 · 0 comments

Comments

@lefth
Copy link

lefth commented Apr 12, 2018

When the exception is cached and throw; is not applicable, another technique is needed to preserve the original exception's context. Storing it as an InnerException is one way, but I think in this case, it's more useful to rethrow it without changing its context:

ExceptionDispatchInfo.Capture(ex).Throw();

A pull request is on the way.

lefth pushed a commit to lefth/Unity3dAsyncAwaitUtil that referenced this issue Apr 12, 2018
When an exception is thrown again ("throw ex"), its stack will be
overwritten. Instead, it should be rethrown with its original context.

More info here (Figure 2):
https://msdn.microsoft.com/en-us/magazine/mt620018.aspx

Issue modesttree#5
lefth pushed a commit to lefth/Unity3dAsyncAwaitUtil that referenced this issue Apr 12, 2018
When an exception is thrown again ("throw ex"), its stack will be
overwritten. Instead, it should be rethrown with its original context.

More info here (Figure 2):
https://msdn.microsoft.com/en-us/magazine/mt620018.aspx

Issue modesttree#5
lefth pushed a commit to lefth/Unity3dAsyncAwaitUtil that referenced this issue Apr 12, 2018
When an exception is thrown again ("throw ex"), its stack will be
overwritten. Instead, it should be rethrown with its original context.

More info here (Figure 2):
https://msdn.microsoft.com/en-us/magazine/mt620018.aspx

Issue modesttree#5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants