How to handle exceptions in a module?

Sep 24, 2008 at 3:45 PM
If my module through an exception, the the GUI does not handle it...
What can I do about it?
Thankx, Harry
Sep 24, 2008 at 6:46 PM



You can subscribe to the UnhandledException event of the Current Application Domain to handle all the exceptions in the Shell project.

Take a look to the App class located in the StockTraderRI project of the Stock Trader Reference Implementation source code. The reference implementation also uses the Exception Handling Application Block to handle the exceptions. The following code is and abstract of the App class.


// App class

private static void RunInReleaseMode()


AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;



UnityBootstrapper bootstrapper = new StockTraderRIBootstrapper();



catch (Exception ex)






private static void AppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)


HandleException(e.ExceptionObject as Exception);



private static void HandleException(Exception ex)


if (ex == null)



ExceptionPolicy.HandleException(ex, "Default Policy");





Please let me know if this helps.


Mariano Converti

Sep 25, 2008 at 6:35 AM
Edited Sep 25, 2008 at 12:07 PM
Thankx Mariano. I have implemented it and it works for some of the exceptions.
It does not work for exceptions, which happens in another "module" / "types".

I have my shell where I load 2 modules:

return new StaticModuleEnumerator()

In Xxx.WpfUi.CommonModule.CommonModule I register the following type:

this.unityContainer.RegisterType<Xxx.Manager.Context>(new ContainerControlledLifetimeManager());

I then use this type in Xxx.WpfUi.FormDocumentModule.FormDocumentModule.

XxxPresenter(IUnityContainer container, IRegionManager regionManager, IFormDocumentNavigationView view, Xxx.Manager.Context dataContext)

If an exception occurs in the Xxx.Manager.Context it does not get thrown back to the module.

Any idea why this is?

Aug 6, 2010 at 5:44 PM

This may not be the correct place to post this, but I'm rather new to Prism and this discussion seems close to what I want to figure out how to do.

I'm looking for a way to catch any and all unhandled exceptions in my WPF Browser Application at the Shell instead of the App. This way we can have a universal error response to indicate a problem has arisen to the user. Any indication to how I can accomplish this would be greatly appreciated.

Feb 4, 2011 at 5:29 PM

I am having the same issues as iwhp1.  I implemented the code provided by Mariano (and the StockTraderRI example project) in app.xaml.cs but I cannot get the AppDomainUnhandledException to handle any expections that occur in a module.  Our hope was to pass all errors on to that exception handler, so we are actually catching and rethrowing errors with the intention of that handler dealing with them all. 

We have considered creating a separate module for error handling and passing errors to that module when we catch them, but we would still like something in place for any unhandled errors that may occur.

Any help on this would be appreciated.

Jan 5, 2012 at 6:14 AM

Thanks a lot, It was really helpfull i was stuck in this problem