吴佳鑫的个人专栏

当日事当日毕,没有任何借口

导航

修炼九阴真经Windows Phone开发 (18):WP 的UI异常处理

 

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 信息。

posted on 2012-09-18 21:45  _eagle  阅读(738)  评论(0编辑  收藏  举报