/// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        /// <summary>
        /// 重写OnStartup函数
        /// </summary>
        /// <param name="e"></param>
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // 保证程序的稳健运行,对程序中未知的异常进行处理【日志方式记录等】
            DispatcherUnhandledException += App_DispatcherUnhandledException;

        }

        /// <summary>
        /// 保证程序的稳健运行,对程序中未知的异常进行处理【日志方式记录等】
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            //throw new NotImplementedException();

            // 修改异常处理标记
            e.Handled = true;
            // 获取异常信息
            string errMsg = e.Exception.Message.ToString();
            // 处理异常、记录日志等.....

            MessageBox.Show("处理了一个异常,信息[" + errMsg + "]");
        }
    }

 

https://www.cnblogs.com/jeremywucnblog/
  本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2022-12-23
猜你喜欢
  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2021-04-02
  • 2021-05-19
相关资源
相似解决方案