Unhandled Exception in Boostrapper

May 10, 2012 at 3:41 PM
Edited May 10, 2012 at 3:49 PM


I am trying to log unhandled exceptions in my WPF application. I would like to achieve following three functions when there is an unhandled exception-


1) Log the exception using Log4Net

2) Show error message 

3) Shut down the application when user clicks ok on the message box.


Here is the code I am using (without the logging piece). Is this the right way to handle the messagebox? What if I want to display WPF toolkit message box using the couroutine? Can some one please point me in the right direction to accomplish above mentioned tasks?


protected override void OnUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
            base.OnUnhandledException(sender, e);
            Execute.OnUIThread(() =>
                           MessageBox.Show(e.Exception.Message, "Application Exception", MessageBoxButton.OK);








Jan 13, 2014 at 10:23 AM
Edited Jan 13, 2014 at 10:43 AM
I too have tried the same thing. It seems that it will work only for exceptions arising from the main (UI) thread.

For my particular case I was able to solve it like this -
var task = new Task(() => ExecuteSomething());
task.ContinueWith(faultedTask =>
            }, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Current);

I have raised an issue here - https://caliburnmicro.codeplex.com/workitem/356