我正在开发一个 Windows Phone 应用程序。我将它提交给 Microsoft,他们给我发回了一个文件,描述了在恢复应用程序时发生的错误(它与 5.2 性能和资源管理,第 5.2.3 点有关)。
为了重现错误,我运行应用程序,从开始按钮开始转到“桌面”,然后单击“返回”按钮。之后,Visual Studio 以黄色突出显示System.Diagnostics.Debugger.Break();
此代码中的行
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
通过堆栈跟踪,我发现最后调用的方法是CallApplicationUEHandler
.
那么,这是一个已知的例外吗?我忘记处理一些异常了吗?
这是 CallApplicationUEHandler 调用上方的最后三行输出:
first chance exception 'System.ArgumentNullException' in Microsoft.Phone.Controls.dll
first chance exception 'System.ArgumentException' in System.Windows.dll
first chance exception 'System.ArgumentException' in System.Windows.dll
构造函数:
对于主页:
public MainPage()
{
journal.Debug(string.Format("Entrée méthode {0}", new StackTrace().GetFrame(1).GetMethod().Name));
InitializeComponent();
Loaded += new RoutedEventHandler(PhoneApplicationPage_Loaded);
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
mainVM = new MainViewModel();
DataContext = mainVM;
}
对于应用程序:
public App()
{
// Global handler for uncaught exceptions.
// Note that exceptions thrown by ApplicationBarItem.Click will not get caught here.
UnhandledException += Application_UnhandledException;
// Standard Silverlight initialization
InitializeComponent();
// Phone- {2} -specific initialization
InitializePhoneApplication();
}
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
}