locked
Exception Handling in MVP RRS feed

  • Question

  • User-1024889423 posted

    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?

    Friday, May 28, 2010 4:02 AM

All replies

  • User-1802908944 posted

    this is very helpfull

    http://www.codeproject.com/KB/aspnet/Exception_FrameWork.aspx




    Friday, May 28, 2010 4:48 AM
  • User-1024889423 posted

    Thank you very much for your answer.

    It seems to me that the person in the article you pointed out agrees with me.

    In facti he is placing try catch blocks both in the presenter and in the view

    providing the view with an Error property to be used by the presenter.

    Any other opinions?

    Friday, May 28, 2010 10:29 AM