天天看點

C# WPF - 修改App.xaml,重寫OnStartup函數來處理不确定的系統異常

/// <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 + "]");             }         }      

  作者:Jeremy.Wu

  出處:https://www.cnblogs.com/jeremywucnblog/

  本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接,否則保留追究法律責任的權利。

繼續閱讀