Exception was unhandled by user code

Topics: Enterprise Library Core, Exception Handling Application Block
Mar 14, 2008 at 8:46 AM
Hi
I get this message "Exception was unhandled by user code" and I'm not able to find out of it. Here is what I got:

Service (implementation):

public Entity LogIn(string username, string password)
{
try
{
}
catch(Exception ex)
{
if(ExceptionPolicy.HandleException(ex, "Service Interface Policy"))
throw; //Here I get Exception was unhandled by user code. I thought the shielding would send an ServiceFault to the client here?
}
}

Shouldn't it be catched on the client next? It never reaches my client. Here is my Web.config configuration:

<exceptionHandling>
<exceptionPolicies>
<add name="Service Interface Policy">
<exceptionTypes>
<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="NotifyRethrow" name="Exception">
<exceptionHandlers>
<add faultContractType="FaultContracts.ServiceFault, FaultContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
exceptionMessage="" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Fault Contract Exception Handler">
<mappings>
<add source="Message" name="Message"/>
<add source="Source" name="Source" />
<add source="StackTrace" name="StackTrace" />
</mappings>
</add>
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>

My TraceStack does not say much either so it want be much help to paste that one in.


Mar 14, 2008 at 1:33 PM
I am not an expert on the EntLib by any means, but shouldn't you set the postHandlingAction to "None" if you have taken care of the exception yourself?
Based on your exception policy configuration the code in the catch block will always rethrow the exception after you had handled it and there is no one else to deal with that exception, so the CLR steps in.

Alex
Mar 21, 2008 at 3:18 PM
Hi,

Please take a look at the "Shielding Exceptions at WCF Service Boundaries" topic in the help file; it describes the steps you need to follow to use the exception shielding feature. You don't really need to deal with the ExceptionPolicy facade yourself; by using the ExceptionShieldingAttribute on your service operation implementation the facade call will be performed for you by a custom WCF error handler.

Btw, by doing

try
{
}
catch(Exception ex)
{
if(ExceptionPolicy.HandleException(ex, "Service Interface Policy"))
throw;
}

you're rethrowing the original exception ex.

Fernando