Exception Handling Policies evaluation

Topics: Exception Handling Application Block
Oct 3, 2011 at 1:20 PM

Hi all,

I'm experiencing an issue with EntLib 4.1 Exception Handling Block.

I have an Exception Plolicy with some Exception Type.

Since one of these types could be derive from other type I'm wondering how the EntLib handler behaves in this case.
Does it apply the policy in the order they are written in the configuration file?

For Example, I have a custom Exception class 

public class MyExceptionType : System.Exception
{
//do stuff
}

an write the following Ent Lib configuration inside application configuration file:

<exceptionHandling>
	<exceptionPolicies>
	<add name="Custom Exception Shielding">
	<exceptionTypes>
	  <add type="MyExceptionType, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=myToken" postHandlingAction="ThrowNewException" name="MyExceptionType">
	    <exceptionHandlers>
	      <add exceptionMessage="" faultContractType="MyFaultContract, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=myToken"
	        type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
	        name="Fault Contract Exception Handler">
	        <mappings>
	          <add source="Message" name="Reason" />
	          <add source="Message" name="Message" />
	          <add source="ErrorId" name="Id" />
	          <add source="ExceptionCategoryName" name="Category" />
	        </mappings>
	      </add>
	    </exceptionHandlers>
	  </add>
	  <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="ThrowNewException" name="GenericException">
	    <exceptionHandlers>              
	      <add exceptionMessage="" faultContractType="AnotherFaultContract, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=myToken"
	        type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
	        name="Fault Contract Exception Handler">
	        <mappings>
	          <add source="Message" name="Reason" />
	          <add source="Message" name="Message" />
	          <add source="ErrorId" name="Id" />
	          <add source="ExceptionCategoryName" name="Category" />
	        </mappings>
	      </add>
	    </exceptionHandlers>
	  </add>
	</exceptionTypes>
	</add>
	</exceptionPolicies>
</exceptionHandling>

Which of the above Exception Type Handler was triggered?

The first one (MyExceptionType) or the secodn one (GenericException) ?

Thanks a lot.

 

Oct 4, 2011 at 2:18 AM

Hi,

That will depend...When logging an exception, you can use the ExceptionManager's HandleException method, and one of its parameters is the name of the policy you want to use.

Check this: http://msdn.microsoft.com/en-us/library/ee763096.aspx

Hope this helps! :-)

Oct 4, 2011 at 7:58 AM

I already done this.

The question is, Which of the above Exception Type Handler was triggered?

Not "Which of the above Exception Policy..."

Oct 4, 2011 at 8:36 AM

Hmm, I think you will have to look in to the Enterprise Library source code for this...

Oct 4, 2011 at 9:18 AM

Hi,

In your case, it will trigger the handler under the MyExceptionType since the EHAB only considers the derived exception type. Hope this helps :)

 

Noel Angelo Bolasoc
Avanade Software and Cloud Services
Avanade, Inc.
Contact