前提・実現したいこと
WPFのアプリケーションで発生する例外がUnhandledExceptionでキャッチできず、
アプリケーションの停止を引き起こしてしまいます。
どうにかキャッチしてログを出力したいのですが、
デバッグ実行できる環境ではないため発生している箇所もわからず対策が取れません。
UnhandledExceptionでキャッチできずアプリケーションが停止する例外には、
どのようなものがありますでしょうか?
該当のソースコード
UnhandledExceptionイベントには下記のように処理を登録しています。
C#
1public partial class App : Application 2{ 3 private void Application_Startup(object sender, StartupEventArgs e) 4 { 5 AppDomain.CurrentDomain.UnhandledException += this.CurrentDomain_UnhandledException; 6 } 7 8 private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) 9 { 10 try 11 { 12 if (e.ExceptionObject is Exception ex) 13 { 14 // ログ出力 15 MessageBox.Show(string.Concat(ex.Message, ex.StackTrace)); 16 } 17 } 18 finally 19 { 20 Current.Shutdown(); 21 } 22 } 23}
回答2件
あなたの回答
tips
プレビュー