Weird unhandled exception's StackTrace behavior in UWP

139 Views Asked by At

In my UWP app's App.xaml.cs file I have the following code to get unhandled exceptions' StackTrace property value and print it to the debug output:

private void OnAppUnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
{
    Exception exceptionThatDoesntGoAway = e.Exception;

    string stackTrace = exceptionThatDoesntGoAway.StackTrace;

    Debug.WriteLine("Exception Stacktrace: " + stackTrace);

    e.Handled = true;
}

I save the Exception to a separate variable as there is another weird behavior where the exception's content gets removed if accessed more than once in case I would need it again.

Then, I save the exception's StackTrace property value to a variable, and then I print it to the debug output.

The problem is that before and after accessing the StackTrace property I get two different outputs:

I watched the exceptionThatDoesntGoAway variable and the StackTrace property in Visual Studio:

enter image description here

This is the StackTrace property value from the exceptionThatDoesntGoAway variable (the first watched item):

enter image description here

While this is the exceptionThatDoesntGoAway.StackTrace property value without line numbers for my app's files (the second watched item):

enter image description here

Why are the values different even if they are the same StackTrace property?

How can I get the first stacktrace with the correct line numbers? Is an expected behavior?

Edit 1: Those are the app's threads at exceptionThatDoesntGoAway.StackTrace access time:

enter image description here

0

There are 0 best solutions below