频道栏目
首页 > 资讯 > 其他综合 > 正文

原来WPF默认处理了这么多Exception,见识了

15-11-10        来源:[db:作者]  
收藏   我要投稿

原来WPF默认处理了这么多Exception,见识了

 

 

 

结果发现CurrentDomain_FirstChanceException这个抛出了很多异常,把相应的异常过滤下:

void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
        {
            if (e.Exception is System.DllNotFoundException||
                e.Exception is System.IO.FileNotFoundException ||
                e.Exception is System.IO.IOException || 
                e.Exception is System.Management.Automation.Host.HostException ||
                e.Exception is System.Management.Automation.ItemNotFoundException||
                e.Exception is System.Management.Automation.PSInvalidCastException||
                e.Exception is System.Management.Automation.PipelineStoppedException||
                e.Exception is System.Management.Automation.CmdletInvocationException||
                e.Exception is System.Management.Automation.PSArgumentException)
            {
                return;
            }
            MessageBox.Show(1. CurrentDomain_FirstChanceException + e.Exception);
            //ProcessError(e.Exception);   - This could be used here to log ALL errors, even those caught by a Try/Catch block 
        }

 

这个是调用Powershell脚本时出现的异常,都忽略掉。

为什么说”原来WPF默认处理了这么多Exception“?因为我没加这段代码前,整个程序是不报错的,加了这个代码之后才有了异常。

我为什么要加这段代码呢?因为我在长时间运行WPF程序之后,出现了“XXX has stopped working”,这说明有异常WPF没有处理掉,想加这个调查下到底哪个异常没有处理导致程序Crash,希望接下来可以看到root cause。

 

 

相关TAG标签
上一篇:如何将数据从Activity返回到Fragment——onActivityResult
下一篇:Android Context完全解析,你所不知道的Context的各种细节
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站