title: Exception handling in n-tier applications?
body: <p>What is the suggested approach or best practice for handling exceptions in tiered applications? </p>
  
  <ul>
  <li>Where should you place <code>try/catch</code> blocks?  </li>
  <li>Where should you implement logging? </li>
  <li>Is there a suggested pattern for managing exceptions in n-tiered applications? </li>
  </ul>
  
  <p>Consider a simple example. Suppose you have a UI, that calls a business layer, that calls a data layer:</p>
  
  <pre><code>//UI
  protected void ButtonClick_GetObject(object sender, EventArgs e) 
  {
      try {
          MyObj obj = Business.GetObj();
      }
      catch (Exception ex) {
          Logger.Log(ex); //should the logging happen here, or at source?
          MessageBox.Show("An error occurred");
      }
  }
  
  //Business
  public MyObj GetObj()
  {
      //is this try/catch block redundant?  
      try {
          MyObj obj = DAL.GetObj();
      }
      catch (Exception ex) {
          throw new Exception("A DAL Exception occurred", ex);
      }
  }
  
  //DAL
  public MyObj GetObj()
  {
      //Or is this try/catch block redundant? 
      try {
          //connect to database, get object
      }
      catch (SqlException ex) {
          throw new Exception("A SQLException occurred", ex);
      }
  }
  </code></pre>
  
  <p>What criticisms would you make of the above exception handling?</p>
  
  <p>thanks </p>