Multiple Exception Handlers for one exception type

Posted by danish on Stack Overflow See other posts from Stack Overflow or by danish
Published on 2010-03-28T06:33:28Z Indexed on 2010/03/28 6:43 UTC
Read the original article Hit count: 1498

I am using Enterprose Library 4.1. I have created a custom exception handler called CustomHandler. This is how the configuration section would look like:

<exceptionHandling>
    <exceptionPolicies>
      <add name="Exception Policy">
        <exceptionTypes>
          <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="NotifyRethrow" name="Exception">
            <exceptionHandlers>
              <add type="WindowsFormsApplication1.CustomHandler, WindowsFormsApplication1"
                name="Custom Handler" />
              <add exceptionMessage="Some test mesage." exceptionMessageResourceName=""
                exceptionMessageResourceType="" replaceExceptionType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                name="Replace Handler" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>

There are two handlers for same exception type. What I want is that based on a certain condition one of the handlers should handle the exception. Any ideas how that can be done?

Is there a way to call the other handler from inside the HandleException method of the custom handler based on some condition?

© Stack Overflow or respective owner

Related posts about c#

Related posts about exception-handling