英文:
Understanding End of stack trace comment in .NET stack traces
问题
I'm trying to correctly read stack traces generated by ASP.NET Core. I don't have a problem finding the cause of an exception. But I see the comment --- End of stack trace from previous location ---
over and over:
Maybe I misunderstood something fundamental about how stack traces are generated. But to my knowledge, the --- End of stack trace ...
string is added when using ExceptionDispatchInfo
to rethrow errors but maintaining the original stack trace:
ExceptionDispatchInfo.Capture(e).Throw();
(Sort of a hybrid between throw
and throw e
)
When looking at the ASP.NET Core source code, it looks to just throw exceptions normally. Can anyone explain why the stack trace is formatted as it is?
英文:
I'm trying to correctly read stack traces generated by ASP.NET Core. I don't have a problem finding the cause of an exception. But I see the comment --- End of stack trace from previous location ---
over and over:
Maybe I misunderstood something fundamental about how stack traces are generated. But to my knowledge, the --- End of stack trace ...
string is added when using ExceptionDispatchInfo
to rethrow errors but maintaining the original stack trace:
ExceptionDispatchInfo.Capture(e).Throw();
(Sort of a hybrid between throw
and throw e
)
When looking at the ASP.NET Core source code, it looks to just throw exceptions normally. Can anyone explain why the stack trace is formatted as it is?
答案1
得分: 1
> 当查看 ASP.NET Core 源代码时,通常看起来只是抛出异常。
但如果您查看提供的堆栈跟踪中的位置,那么您将看到 ExceptionDispatchInfo.Capture(e).Throw()
。
例如,在 ResourceInvoker.InvokeNextResourceFilter 中:
catch (Exception exception)
{
_resourceExecutedContext = new ResourceExecutedContextSealed(_resourceExecutingContext!, _filters)
{
ExceptionDispatchInfo = ExceptionDispatchInfo.Capture(exception),
};
}
使用 ExceptionDispatchInfo.Capture()
的原因在 https://stackoverflow.com/questions/45723327/whats-the-point-of-passing-exceptiondispatchinfo-around-instead-of-just-the-exc 中有很好的解释。
英文:
You wrote:
> When looking at the ASP.NET Core source code, it looks to just throw exceptions normally.
But if you look at the places you have in the provided stack trace then you'll see ExceptionDispatchInfo.Capture(e).Throw()
.
E.g. in ResourceInvoker.InvokeNextResourceFilter:
catch (Exception exception)
{
_resourceExecutedContext = new ResourceExecutedContextSealed(_resourceExecutingContext!, _filters)
{
ExceptionDispatchInfo = ExceptionDispatchInfo.Capture(exception),
};
}
The reason for using ExceptionDispatchInfo.Capture()
is well explained in https://stackoverflow.com/questions/45723327/whats-the-point-of-passing-exceptiondispatchinfo-around-instead-of-just-the-exc
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论