From 8ef6827bd97928002a556b2d0647b882458fb65c Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Tue, 11 Mar 2014 21:52:29 +0800 Subject: [PATCH] Add global unhandled exception check. --- Wox/MainWindow.xaml.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 80f2f2482..81a145771 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -45,6 +45,9 @@ public partial class MainWindow public MainWindow() { InitializeComponent(); + + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + progressBar.ToolTip = toolTip; InitialTray(); resultCtrl.OnMouseClickItem += AcceptSelect; @@ -64,6 +67,19 @@ public MainWindow() SetCustomPluginHotkey(); } + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + if (!System.Diagnostics.Debugger.IsAttached) + { + string error = "Wox has an error that can't be handled. " + e.ExceptionObject; + Log.Error(error); + if (e.IsTerminating) + { + MessageBox.Show(error); + } + } + } + public void SetHotkey(string hotkeyStr, EventHandler action) { var hotkey = new HotkeyModel(hotkeyStr);