我有一个Windows Phone 8.1 RT应用程序。在应用程序中,我订阅了UnhandledException
事件,该事件在应用程序中发生任何未处理的异常时引发。我将此事件绑定到事件处理程序,该事件处理程序由事件传递UnhandledExceptionEventArgs
。
UnhandledExceptionEventArgs
有一个属性Exception
,其属性为Stacktrace
。问题是,我只能访问stacktrace属性一次,因为它在我访问后变为null。
当遇到任何断点并且您尝试使用游标或立即窗口访问参数中包含的值时,也可以观察到这种奇怪的行为。一旦我将鼠标悬停在光标或访问即时窗口中的值,它就会变为空。
在阅读UnhandledExceptionEventArgs
属性之前,当我读取Stacktrace
的任何属性时,它也会导致问题。比如说,如果e
的类型为UnhandledExceptionEventArgs
,其中包含Message
和Exception
个对象,则在访问e.Message
之前访问e.Exception.Stacktrace
会使e.Exception.Stacktrace
中的值包含在dplyr
中1}} null。
知道为什么会出现这种奇怪的行为吗?
答案 0 :(得分:1)
不确定是否是这种情况,但MSDN说:
UnhandledException事件参数公开异常对象 通过Exception属性。但是,类型,消息和堆栈 此异常对象的跟踪不保证与那些匹配 引发的原始异常
答案 1 :(得分:0)
这似乎是一个问题:Improper WinRT exception behavior
在读取 UnhandledExceptionEventArgs 类的任何属性之前,应将 UnhandledExceptionEventArgs.Exception 值保存到变量中。 之后,您可以通过读取变量值(不是 UnhandledExceptionEventArgs.Exception 值)随时访问任何信息(如堆栈跟踪)。
答案 2 :(得分:-1)
尝试使用属性 UnhandledExceptionEventArgs.Message
比较
Application.Current.UnhandledException += (sender, args) =>
{
Debug.WriteLine(args.Exception.ToString()); // {"Exception of type 'System.Exception' was thrown."}
Debug.WriteLine(args.Exception.Message); // "Exception of type 'System.Exception' was thrown."
Debug.WriteLine(args.Message); // "System.Exception: Exception of type 'System.Exception' was thrown.\r\n at AppMetrica.Demo.MainPage.<>c.<.ctor>b__0_2(Object sender, RoutedEventArgs args)"
};