Over the course of six months of Winforms-MVP, I developed the following exception handling strategy. I have a base abstract class Presenter with several Execute methods that take a delegate as an input parameter (signatures change). The interaction between the presentation and the presenter is carried out using events (input) defined in IView, and by setting public properties (output) or calling methods defined in IView, as well as implemented by View. Each event handler in the presenter calls one of the Execute methods, providing it with a specific implementation.
In the execution method, I have several catch blocks for very specific exceptions that may occur (mainly due to some problems in external components that are widely used). Each of these exceptions stops the execution of the current operation, registers and displays to the user with a meaningful explanation, calling the viewing methods.
Not so long ago (actually VERY not so long ago) I began to study WPF-MVVM, which at first glance seems to have a lot in common with MVP. I was looking for some useful tips regarding the exception handling strategy there (mostly informing the user about the problems), but these questions are hard to find at all - I mean, a lot has been said, but mainly in principle. I found more than 20 examples of "handling" unhandled exceptions in app.xaml.cs, all of which are very nice, but tell me sincerely - if you know the exact exceptions that could lead to an application crash, would you handle them a little earlier (even if you will be forced to close the application)? I am not a fan of all possible exceptions. Quite a few exceptions caused by network problems, temporary unavailability of the database, etc., should be handled without closing the application without errors and errors, which gives ordinary users the opportunity to repeat its request.
So, as an experiment, I tried almost the same thing that I described earlier - I created events in the ViewModel to jump to exceptions and subscribed to them. But honestly, this path gives me crawls.
(It was a very long speech, I know) Question: how do you handle exceptions in terms of informing the user when using MVVM? No, at the moment I'm not interested in data verification. Any criticism and / or advice on MVP is also welcome.
source share