开发者

Caliburn - Exception handling and Rescue

开发者 https://www.devze.com 2023-01-09 23:57 出处:网络
开发者_如何学编程I\'m using C# and Caliburn. Is there a global way to catch all exceptions in all view models?

开发者_如何学编程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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消