Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinRt. UnhandledException handler. StackTrace is null

I have a project on WinForms with this code:

AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;

private void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{            }

The e.ExceptionObject contains full StackTrace.

In Win Store project:

this.UnhandledException += (s, e) =>{                                               
{                                              
    MarkedUp.AnalyticClient.LogLastChanceException(e);
};

e.Exception.StackTrace is null.

Both exceptions were generated by this code:

int a=0;
....

try
{
    int i = 1 / a;
}
catch (Exception exp)
{
    throw;
}

Any Ideas?

like image 952
d.lavysh Avatar asked Nov 03 '22 20:11

d.lavysh


2 Answers

The reference on MSDN suggests that this is a limitation: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.application.unhandledexception

A notable limitation is that the UnhandledException event arguments don’t contain as much detail as the original exception as propagated from app code. Whenever possible, if the app requires specific processing of a certain exception, it’s always better to catch the exception as it propagates, because more detail will be available then. 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. The event arguments do expose a Message property. In most cases, this will contain the message of the originally raised exception.

like image 180
Vasiliy Kulakov Avatar answered Jan 04 '23 14:01

Vasiliy Kulakov


Are you running the solution in Debug mode? There seems to be happening something in the App.g.i.cs file when you run the solution in Debug mode. When I run your sample in Release mode the stacktrace is available in the UnhandledException event.

In my test solution it breaks first here:

#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
            UnhandledException += (sender, e) =>
            {
                if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
            };
#endif

And after that one it goes to the UnhandledException handler that I have defined in the app.xaml.cs file. In Debug the stacktrace is gone, in Release mode the stacktrace and the exception details are there.

like image 42
ChristiaanV Avatar answered Jan 04 '23 14:01

ChristiaanV