zoukankan      html  css  js  c++  java
  • Windows Phone 7 异常的人性化处理

    今天在学习 Windows Phone 7WP7() 编程时,接触到 WP7 的异常处理。
    主要是异常的人性化显示。

    在 App.xaml.cs 的 RootFrame_NavigationFailed (自动生成的) 函数中对 e.Handled 进行赋值。
    先看未修改的代码:

    1 private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)  
    2  {  
    3             if (System.Diagnostics.Debugger.IsAttached)  
    4             {  
    5                 // A navigation has failed; break into the debugger  
    6                 System.Diagnostics.Debugger.Break();  
    7             }  
    8 }

    修改后的代码:

    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 控件中。当然,如果为了让“用户”看懂异常信息,直接这样显示是不行的。需要将这种“计算机”语言转为自然语言。

    其中,关键的一句是:

    1 e.Handled = true;

    如果没有此句,系统会将异常最终传递到:Application_UnhandledException() 函数中进行处理,并导致应用程序直接关闭。

  • 相关阅读:
    《MobileNetV2: Inverted Residuals and Linear Bottlenecks》论文阅读
    CF1464D The Thorny Path
    Codeforces Global Round #12
    欧拉数 (Eulerian Number)
    CF1437F Emotional Fishermen
    CF1408G Clusterization Counting
    [PA2013] Filary
    Codeforces Educational Round #95 题解
    [清华集训2016] 你的生命已如风中残烛
    [题解] lxxx
  • 原文地址:https://www.cnblogs.com/91program/p/5206514.html
Copyright © 2011-2022 走看看