Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stacktrace reported by UnhandledExceptionEventArgs exception becomes null after extracting once

I have a Windows Phone 8.1 RT application. In the app, I subscribe to UnhandledException event which is raised when any unhandled exception occurs in the application. I bind this event to an event handler, which is passed UnhandledExceptionEventArgs by the event.

UnhandledExceptionEventArgs has a property Exception, which has a property Stacktrace. The problem is, I'm only able to access the stacktrace property only once, as it becomes null after I access it.

This weird behavior can also be observed when any breakpoint is hit and you try to access the value contained in the argument using the cursor or the immediate window. Once I hover the cursor or access the value in the immediate window, it becomes null afterwards.

It also causes an issue when I read any property of UnhandledExceptionEventArgs before reading the Stacktrace property. Say, if e is of type UnhandledExceptionEventArgs containing Message and Exception object, accessing e.Message before accessing e.Exception.Stacktrace makes the value contained in e.Exception.Stacktrace null.

Any idea why this odd behavior is observed?

like image 993
nimbudew Avatar asked Feb 17 '26 03:02

nimbudew


2 Answers

Not sure if this is the case, but MSDN says:

The UnhandledException event arguments expose an exception object through the Exception property. However, the type, message, and stack trace of this exception object are not guaranteed to match those of the original exception that was raised

like image 110
Matteo Umili Avatar answered Feb 18 '26 15:02

Matteo Umili


This seems to be an issue: Improper WinRT exception behavior

You should save UnhandledExceptionEventArgs.Exception value to a variable before reading any properties of UnhandledExceptionEventArgs class. After that you can access any information (like stack trace) at any moment by reading your variable value(not UnhandledExceptionEventArgs.Exception value).

like image 40
Evgeny Gorbovoy Avatar answered Feb 18 '26 15:02

Evgeny Gorbovoy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!