Handling Unhandled Exceptions

Sep 27, 2007 at 5:26 AM
In CabApplication there is a check to see if our application overrides OnUnhandledException (public virtual void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)) This is an unhandled exception handler for .NET 2.0 unhandled exceptions.

When working in WPF, the reccomended approach is to subscribe to the DispatcherUnhandledException.

In my current application I have the following inheritance hierarchy
ShellApplication -> SmartClientApplication
SmartClientApplication -> ApplicationShellApplication
ApplicationShellApplication -> WindowsApplication

ShellApplication contains my main method, which creates an instance of ShellApplication and invokes ShellApplication.Run.

I am overriding BeforeShellCreated and AfterShellCreated. I can write the following code to hook up to the DispatcherUnhandledException even of Application BUT ONLY AFTER the call to AfterShellCreated.

App.Current.DispatcherUnhandledException += HandleAppUnhandledException;

App.Current is null until after the call to AfterShellCreated.

So what happens when we get an unhandled exception before AfterShellCreated is called? What is the reccomended practices when working with pure wpf solutions using SCSFContrib?