Wrapped Exception Type

Topics: Exception Handling Application Block
May 1, 2008 at 9:59 AM
Good Morning

I am currently using the exception handling block from release 3.1.

The library is being used as part of my c# web application, I am having a problem with wrapping an exception.

For testing purposes, what I am doing is throwing a DBConcurrencyException on my Page_Load event, catching it and applying a DataAccess policy to it:

try {
throw new System.Data.DBConcurrencyException("Original Exception: Problem in business layer"); }
catch (Exception error) {
bool rethrow = ExceptionPolicy.HandleException(error, "DataAccess");
if (rethrow)

So in my Web.config I have this exception policy:

<add name="DataAccess">
<add name="DBConcurrencyException" type="System.Data.DBConcurrencyException, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="ThrowNewException">
<add name="Wrap Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" exceptionMessage="Wrapped Exception: A recoverable error occurred while attempting to access the database." wrapExceptionType="ExceptionHandlingQuickStart.BusinessLayer.BusinessLayerException, ExceptionHandlingQuickStart.BusinessLayer" />

In the Global.asax I have the Application_Error event performing the following:

void Application_Error(object sender, EventArgs e)
// Code that runs when an unhandled error occurs
Exception ex = Server.GetLastError();

What I was expecting to see was the ServerGetLastError() to return an exception of type, BusinessLayerException but its actually coming back as a System.Web.HttpUnhandledException. If I examine the inner exception by Server.GetLastError().InnerException I find my BusinessLayerException.

So I was wondering if this is what is expected or if I have an exception occuring somewhere else which is causing the System.Web.HttpUnhandledException?

May 5, 2008 at 4:09 PM

The HttpUnhandledException is itself a wrapper exception created by the ASP.NET runtime. If you take a look at its stack trace you can see where it's being thrown.