From bf4781dbde2a370ea51acbea6550382a77e008f3 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 2 Jul 2015 22:02:51 +0100 Subject: [PATCH] Added application-level unhandled exception handler --- Filtration/App.xaml.cs | 17 ++++++++++++++--- Filtration/ViewModels/MainWindowViewModel.cs | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Filtration/App.xaml.cs b/Filtration/App.xaml.cs index b7c7082..7c7c9c6 100644 --- a/Filtration/App.xaml.cs +++ b/Filtration/App.xaml.cs @@ -1,6 +1,8 @@ -using System.IO.Compression; +using System; +using System.IO.Compression; using System.Linq; using System.Windows; +using System.Windows.Threading; using AutoMapper; using Castle.Facilities.TypedFactory; using Castle.MicroKernel.ModelBuilder.Inspectors; @@ -57,14 +59,23 @@ namespace Filtration Mapper.CreateMap(); Mapper.AssertConfigurationIsValid(); + DispatcherUnhandledException += OnDispatcherUnhandledException; var mainWindow = _container.Resolve(); mainWindow.Show(); } - public void TestTest() + public void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { - + var exception = e.Exception.Message + Environment.NewLine + e.Exception.StackTrace; + var innerException = e.Exception.InnerException != null + ? e.Exception.InnerException.Message + Environment.NewLine + + e.Exception.InnerException.StackTrace + : string.Empty; + + MessageBox.Show( + exception + Environment.NewLine + innerException, + "Unhandled Exception", MessageBoxButton.OK, MessageBoxImage.Error); } protected override void OnExit(ExitEventArgs e) diff --git a/Filtration/ViewModels/MainWindowViewModel.cs b/Filtration/ViewModels/MainWindowViewModel.cs index 720fddd..453df95 100644 --- a/Filtration/ViewModels/MainWindowViewModel.cs +++ b/Filtration/ViewModels/MainWindowViewModel.cs @@ -139,6 +139,7 @@ namespace Filtration.ViewModels } }); CheckForUpdates(); + throw new Exception("Test of dispatcher exception handler"); } public RelayCommand OpenScriptCommand { get; private set; }