Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

There is a really simple way to achieve this, just override the UnhandledException method in your Bootstrapper.

There is an example here: Global handling exception in WPF app with Caliburn.Micro

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top