Unable to handle exception: SqlExceptionWrapHandler

Feb 28, 2008 at 10:06 AM
Hi,

I have a UI and separate data access project.
The data access project is catching a Unique Key violation
catch (Exception ex)
{
if (ExceptionHandler.HandleException(ex, Policy.DatabasePolicy))
{
throw;
}
}

but as soon as the "if (ExceptionHandler.HandleException(ex, Policy.DatabasePolicy))" is called, I get thrown back to the UI, which is the next catch block up, and by then it is "Unable to handle exception: SqlExceptionWrapHandler"
Stack trace:
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.ExecuteHandlerChain(Exception ex, Guid handlingInstanceID)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.Handle(Exception exceptionToHandle)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl.HandleException(Exception exceptionToHandle)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName, ExceptionPolicyFactory policyFactory)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName)
at MyApp.Exceptions.ExceptionHandler.HandleException(Exception exceptionToHandle, Policy policy)
at MyApp.Model.Managers.TaskManager.Save(String userId, Task task)
at MyApp.GUI.Tasks.TasksMain.cmdSave_Click(Object sender, EventArgs e) in C:\Development\GUI\GUI\Tasks\TasksMain.cs:line 748

My exceptions policiies in the GUI.,config contains:
<add name="DatabasePolicy">
<exceptionTypes>
<add type="System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="ThrowNewException" name="SqlException">
<exceptionHandlers>
<add defaultExceptionMessage="" defaultWrapExceptionType="System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
errorCodeNotConfiguredBehavior="WrapWithDefaultException" type="EntLibContrib.ExceptionHandling.SqlExceptionWrapHandler, EntLibContrib.ExceptionHandling, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
name="SqlException Wrap Handler">
<errorCodes>
<add errorCode="547" wrapExceptionTypeName="MyApp.Exceptions.ForeignKeyException, MyApp.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
exceptionMessage="This Record is referenced elsewhere in MyApp."
name="Foreign Key Violation" />
</errorCodes>
</add>
</exceptionHandlers>
</add>
</exceptionTypes>
</add>

Does anyone have any idea what is causing this problem and how I might fix it?
Error Code 547 messages ARE being caught correctly. I want "unhandled" exceptions just to use some generic exception I define, or even to throw the original exception.

thanks in advance for your help.