tags:

views:

72

answers:

1

I'm using C# and Caliburn.

Is there a global way to catch all exceptions in all view models?

What about when there is some kind of exception during import from a DI/IoC container?

I basically want to display a message box when this occurs.

The RescueAttribute looks to me like it would have to be put on every single view model class, and it doesn't seem like it works when you use AsyncActionAttribute at the same time.

+2  A: 

The method IConventionManager.ApplyActionCreationConventions(IAction action, IMethod targetMethod) is invoked just after an action creation and can add filters to it.

You can provide a custom IConventionManager overriding DefaultConventionManager.ApplyActionCreationConventions and pushing in the action a rescue filter.

Note that in this case you have to provide a rescue method on every ViewModel anyway; to overcome this, you can build a new custom rescue filter (following the line of the original one) and dispatch the exception to your infrastructure.

Marco Amendola
I will look into this.
Jonathan.Peppers