Reputation: 5229
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?
Upvotes: 2
Views: 912
Reputation: 2415
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 What's the point of passing ExceptionDispatchInfo around instead of just the Exception?
Upvotes: 2