[WPF]使用DispatcherUnhandledException捕捉未经处理的异常

使用DispatcherUnhandledException捕捉未经处理的异常

using System.Windows;

namespace Test02
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            this.DispatcherUnhandledException += App_DispatcherUnhandledException;
        }

        void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            MessageBox.Show(e.Exception.Message);
        }
    }
}

  

posted @ 2022-02-16 16:56  xiaoshuye  阅读(142)  评论(0编辑  收藏  举报