Some issues with Exception Handling Logging

Topics: Exception Handling Application Block
Jan 10, 2007 at 11:12 AM
I have a 3 tier ASP.NET 2 web application using Enterprise Library for DataAccess, Exception hadling and logging.

The questions that I have are:

I am handling my exceptions in the DAL for any data access exception. For this I normally do.

catch (System.Exception exc)
MeroException mExc = new MeroException("Une erreur est survenue lors de la récupération de la liste des salles de l'étage n°" + floorID, exc);
bool rethrow = ExceptionPolicy.HandleException(mExc, "Exception Policy");
if (rethrow)
throw mExc;
And for any other error that could occur in the application I am trying to handle the errors in the Application_Error handler in the Global.asax

System.Exception exc = Server.GetLastError().GetBaseException();
ExceptionPolicy.HandleException(exc, "Exception Policy");

The excpetion logging has two listeners Email and EventLog. Now when an error occurs in the DAL it is first handled there and then in the Global.asax as well. So the exceptions are logged twice and there is an advertisement in the EventLog as well stating that Unhandled error occured in the application.

My question is what is the best approach to avoid multiple logs for the same entry and avoid these advertisements(I am just wondering why is it Unhandled).

Should I just throw the exception in the DAL and handle all the exception in the Global.asax.
And to avoid Advertisements should I clear the error? But in that case how will the user be redirected to the Error page. Should I do the Response.Redirect towards the error page in that case??

Looking to find the best approach.

Jan 18, 2007 at 5:57 PM
It sounds like you would be better off just throwing the exceptions in the DAL and letting Application_Error catch them.

Then just log the exception in the Application_Error event handler using the logging application block and let ASP.NET take the user directly to the custom error page.




David Hayden
Microsoft MVP C#
Jan 19, 2007 at 8:40 AM
Ok thanks a lot.