如何防止不是由用户代码引起的异常?
How can I prevent exceptions that aren't caused by user code?
我在商店中有一个 Windows Phone 8.1 应用程序似乎崩溃了。这通常很容易修复,但异常似乎发生在 Windows API 的深处。当我最初开发我的应用程序时,我从未遇到过任何这些异常。我也在网上搜索过,但似乎找不到关于这些的任何信息。
Here's an Excel Online workbook with stack trace and exception data. (OneDrive)
我的问题是,如何解决这些异常并防止它们在未来发生?
无法捕获 Windows Phone 应用程序上的所有异常,因为其中一些异常是由 OS 级别的不稳定性引起的。但是,您可以通过设置全局异常处理程序来捕获其中的许多异常。
首先,在app构造函数中订阅UnhandledException
事件:
public App()
{
this.InitializeComponent();
this.UnhandledException += App_UnhandledException;
}
在事件处理程序中,将 e.Handled
设置为 true
:
void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
e.Handled = true;
}
我还建议添加一种方法来记录异常并自动将它们发送给您,因为您可能隐藏了您 could/should 修复的合法错误。
我在商店中有一个 Windows Phone 8.1 应用程序似乎崩溃了。这通常很容易修复,但异常似乎发生在 Windows API 的深处。当我最初开发我的应用程序时,我从未遇到过任何这些异常。我也在网上搜索过,但似乎找不到关于这些的任何信息。
Here's an Excel Online workbook with stack trace and exception data. (OneDrive)
我的问题是,如何解决这些异常并防止它们在未来发生?
无法捕获 Windows Phone 应用程序上的所有异常,因为其中一些异常是由 OS 级别的不稳定性引起的。但是,您可以通过设置全局异常处理程序来捕获其中的许多异常。
首先,在app构造函数中订阅UnhandledException
事件:
public App()
{
this.InitializeComponent();
this.UnhandledException += App_UnhandledException;
}
在事件处理程序中,将 e.Handled
设置为 true
:
void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
e.Handled = true;
}
我还建议添加一种方法来记录异常并自动将它们发送给您,因为您可能隐藏了您 could/should 修复的合法错误。