Communication between layers in an application

Posted by Petar Minchev on Stack Overflow See other posts from Stack Overflow or by Petar Minchev
Published on 2010-03-27T08:09:36Z Indexed on 2010/03/27 8:13 UTC
Read the original article Hit count: 262

Hi guys!

Let's assume we have the following method in the business layer. What's the best practice to tell the UI layer that something went wrong and give also the error message? Should the method return an empty String when it was OK, otherwise the error message, or should it throw another exception in the catch code wrapping the caught exception? If we choose the second variant then the UI should have another try,catch which is too much try,catch maybe. Here is a pseudocode for the first variant.

public String updateSomething()
{
   try
   {
      //Begin transaction here
      dataLayer.do1();
      dataLayer.do2();
      dataLayer.doN();
   }
   catch(Exception exc)
   {
      //Rollback transaction code here
      return exc.message;
   }

   return "";
 }

Is this a good practice or should I throw another exception in the catch(then the method will be void)?

© Stack Overflow or respective owner

Related posts about layers

Related posts about exception-handling