UI异常处理:
在app.xaml.cs 中,有这样两个方法:
// 导航失败时执行的代码
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// 导航已失败;强行进入调试器
System.Diagnostics.Debugger.Break();
}
}

// 出现未处理的异常时执行的代码
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// 出现未处理的异常;强行进入调试器
System.Diagnostics.Debugger.Break();
}
}


通过注释可以很清楚地看到,这两个方法可以用来帮助处理错误和异常。
RootFrame_NavigationFailed 用来处理导航失败。第二个方法Application_UnhandledException用来处理应用程序所有未处理的异常(没有某个环节捕获的异常)
如果是在调试模式下, System.Diagnostics.Debugger.Break();将会使得断点停留在此处。这是一个很实用的功能,程序员有机会在这里查看runtime 信息。

相关文章:

  • 2022-02-10
  • 2021-07-29
  • 2021-07-09
  • 2021-09-17
  • 2022-01-29
  • 2022-02-26
  • 2021-10-28
  • 2021-09-21
猜你喜欢
  • 2021-09-23
  • 2021-12-22
  • 2022-03-07
  • 2022-01-27
  • 2021-10-26
  • 2021-05-28
  • 2021-11-04
相关资源
相似解决方案