title: Exception Handling in PageBase ASP.NET Web form?
body: <p>1)I have the PageBase class that inherits from Page Class. The all code behind inherit from PageBase class. So I want to add the exception handling logic to PageBase class.</p>
  
  <p>In Page_Error Event I added the logic to handle the exception, but the I want page to be rendered properly with exception details showing on the top of Web Page.</p>
  
  <p>e.g</p>
  
  <p>On web form I have button control that updates the data in Database. On button click i have the logic to update the data. While updating it may throw exception. I dont want to put Try catch block on button click save logic. Instead I want some method or event on PageBase to catch the exception and render the page entirely with all controls and exception in the header.</p>
  
  <p>2)`// in the Base class of CodeBehind page, I have Written</p>
  
  <pre><code>protected void TryAction(Action action)
  {
    try
    {
      action();
    }
    catch(Exception e)
    {
      // write exception to output (Response.Write(str))
    }
  }
  </code></pre>
  
  <p>In CodeBehind I have written the code for Button Click Event</p>
  
  <pre><code>Private List&lt;T&gt; GetData(string a, string b)
  {
    List&lt;T&gt; _lst;
    TryAction(()=&gt;{
       //Call BLL Method to retrieve the list of BO.
       _lst = BLLInstance.GetAllList(a,b);
    });
    return _lst;
  }
  </code></pre>
  
  <p>This Works fine, I want,</p>
  
  <pre><code>Private List&lt;T&gt; GetData(string a, string b)
  {
    TryAction(()=&gt;{
       //Call BLL Method to retrieve the list of BO.
       return BLLInstance.GetAllList(a,b);
    });
  }
  </code></pre>
  
  <p>It is Showing the Error"System.Action retuens void", Can you please tell me how to use TryAction Method if we have return type.</p>