.NET堆栈跟踪中的”End of stack trace”注释的理解

huangapple go评论64阅读模式
英文:

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:

.NET堆栈跟踪中的”End of stack trace”注释的理解

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:

.NET堆栈跟踪中的”End of stack trace”注释的理解

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

huangapple
  • 本文由 发表于 2023年2月6日 17:12:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75359313.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定