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.
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.
e.g
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.
2)`// in the Base class of CodeBehind page, I have Written
protected void TryAction(Action action)
{
try
{
action();
}
catch(Exception e)
{
// write exception to output (Response.Write(str))
}
}
In CodeBehind I have written the code for Button Click Event
Private List<T> GetData(string a, string b)
{
List<T> _lst;
TryAction(()=>{
//Call BLL Method to retrieve the list of BO.
_lst = BLLInstance.GetAllList(a,b);
});
return _lst;
}
This Works fine, I want,
Private List<T> GetData(string a, string b)
{
TryAction(()=>{
//Call BLL Method to retrieve the list of BO.
return BLLInstance.GetAllList(a,b);
});
}
It is Showing the Error"System.Action retuens void", Can you please tell me how to use TryAction Method if we have return type.