• 解决WPF中异常导致的程序Crash


    通常在WPF中出现异常,会导致程序Crash,即使把异常Throw出来,依旧会报错,解决方法只需在App.xaml.cs中进行处理即可,废话不说,代码如下:

    private int exceptionCount;

    private void Application_Startup(object sender, StartupEventArgs e)
    {
    AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
    Current.DispatcherUnhandledException += Application_DispatcherUnhandledException;
    }

    private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
    {
    //"I'm sorry, the current application occured some issues.." +
    if (exceptionCount > 0) { exceptionCount = 0; e.Handled = true; return; }
    MessageWindow.Show(MessageLevel.Error, e.Exception.Message);
    exceptionCount++;
    e.Handled = true;
    }

    private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
    Exception ex = e.ExceptionObject as Exception;
    MessageWindow.Show(MessageLevel.Error, ResourceHelper.GetRsByKey("LOC_Error_00002") + e.ExceptionObject);
    }

  • 相关阅读:
    MySQL 管理
    CSS font-style 属性
    HTML DOM Input Search value 属性
    tan (Numerics) – C 中文开发手册
    Java8中的Java.util.StringJoiner
    ASP ShortPath 属性
    java.lang.NoClassDefFoundError的解决方案
    HTML DOM td , th 对象
    HTML colgroup char 属性
    Java 之 递归&递归操作文件
  • 原文地址:https://www.cnblogs.com/zunzunQ/p/6729685.html
Copyright © 2020-2023  润新知