Windows Phone 7 异常的人性化处理
2016-02-22 11:08
197 查看
今天在学习 Windows Phone 7WP7() 编程时,接触到 WP7 的异常处理。
主要是异常的人性化显示。
在 App.xaml.cs 的 RootFrame_NavigationFailed (自动生成的) 函数中对 e.Handled 进行赋值。
先看未修改的代码:
修改后的代码:
将异常信息直接显示在 Page 1 页面的 Text 控件中。当然,如果为了让“用户”看懂异常信息,直接这样显示是不行的。需要将这种“计算机”语言转为自然语言。
其中,关键的一句是:
如果没有此句,系统会将异常最终传递到:Application_UnhandledException() 函数中进行处理,并导致应用程序直接关闭。
主要是异常的人性化显示。
在 App.xaml.cs 的 RootFrame_NavigationFailed (自动生成的) 函数中对 e.Handled 进行赋值。
先看未修改的代码:
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) { // A navigation has failed; break into the debugger System.Diagnostics.Debugger.Break(); } }
修改后的代码:
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) { // A navigation has failed; break into the debugger System.Diagnostics.Debugger.Break(); } e.Handled = true; Page1.ExceptionInfo = e.Exception; (RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame).Source = new Uri("/Page1.xaml", UriKind.Relative); }
将异常信息直接显示在 Page 1 页面的 Text 控件中。当然,如果为了让“用户”看懂异常信息,直接这样显示是不行的。需要将这种“计算机”语言转为自然语言。
其中,关键的一句是:
e.Handled = true;
如果没有此句,系统会将异常最终传递到:Application_UnhandledException() 函数中进行处理,并导致应用程序直接关闭。
相关文章推荐
- 视频中发光物体的颜色显示问题
- Android中onMeasure方法的理解
- 2016年1月国内浏览器市场份额:Chrome领先IE4.9%
- Webview实现android简单的浏览器实例代码
- 元宵节作业
- 指向指针的引用
- 利用JS实现的根据经纬度计算地球上两点之间的距离
- 初次运行 Git 前的配置
- UILabel,文字添加下划线,中划线
- android 获取图片
- 7. Reverse Integer
- 错误集锦
- 秒杀方案总结
- Apache Shiro 使用手册
- JAVA单例模式
- Android AIDL使用详解
- 没有找到mfc100.dll
- CKEditor使用Code Snippet让代码高亮显示
- spi测试代码
- fir.im Weekly - 2016 开年技术干货分享