Exception Handling in MVP Passive View

Posted by ilmatte on Stack Overflow See other posts from Stack Overflow or by ilmatte
Published on 2010-06-16T10:06:48Z Indexed on 2010/06/16 10:12 UTC
Read the original article Hit count: 251

Filed under:
|
|

Hello,

I'm wondering what's the preferred way to manage exceptions in an MVP implemented with a Passive View.

There's a discussion in my company about putting try/catch blocks in the presenter or only in the view.

In my opinion the logical top level caller is the presenter (even if the actual one is the view).

Moreover I can test the presenter and not the view. This is the reason why I prefer to define a method in the view interface:

IView.ShowError(error)

and invoke it from the catch blocks in the presenter:

try

{

}

catch (Exception exception)

{

...log exception...

view.ShowError("An error occurred")

}

In this way the developers of future views can safely forget to implement exception handling but the IView interface force them

to implement a ShowError method.

The drawback is that if I want to feel completely safe I need to add redundant try/catch blocks in the view.

The other way would be to add try catch blocks only in the views and not introducing the showerror method in the view interface.

What do you suggest?

© Stack Overflow or respective owner

Related posts about c#

Related posts about exception-handling