locked
Why does Enterprise Library ExceptionPolicy.HandleException return true/false? RRS feed

  • Question

  • User48651432 posted

    I've been googling this topic, and I have seen several examples, but I'm not sure how it works.

    Anyways, this is a portion of code:

    try
    {
       throw new Exception
          ("This is a test exception");
    }
    catch (Exception ex)
    {                
       bool rethrow = ExceptionPolicy.HandleException (ex, "BusinessLogicPolicy");                       
       if (rethrow)
       {
          throw;
       }
    }
    I understand the general concept, but I don't understand what's being checked that returns true or false...

    Why would this following line return true/false? bool rethrow = ExceptionPolicy.HandleException (ex, "BusinessLogicPolicy");

    With two exception policies below, why would an ex return true for one but false for another one?

             <add name="BusinessLogicPolicy">
                <exceptionTypes>
                   <add name="All Exceptions" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                      postHandlingAction="ThrowNewException">
                      <exceptionHandlers>
                         <add name="BusinessLogicLoggingHandler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                            logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                            formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                            priority="0" />
                         <add name="BusinessLogicReplaceHandler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                            exceptionMessage="An unknown error has occurred in Business Logic Layer while processing your request. Please contract Help Desk Support at X-XXX-XXX-XXXX with Error Token ID {handlingInstanceID}."
                            replaceExceptionType="Common.Helpers.ExceptionHandling.BusinessLogicException, Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
                      </exceptionHandlers>
                   </add>
                </exceptionTypes>
             </add>

            <add name="DataAccessPolicy">
                <exceptionTypes>
                   <add name="All Exceptions" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                      postHandlingAction="ThrowNewException">
                      <exceptionHandlers>
                         <add name="DataAccessLoggingHandler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                            logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                            formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                            priority="0" />
                         <add name="DataAccessReplaceHandler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                            exceptionMessage="An unknown error has occurred in Data Access Layer while processing your request. Please contract Help Desk Support at X-XXX-XXX-XXXX with Error Token ID {handlingInstanceID}."
                            replaceExceptionType="Common.Helpers.ExceptionHandling.DataAccessException, Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
                      </exceptionHandlers>
                   </add>
                </exceptionTypes>
             </add>
    
    Friday, December 9, 2011 8:40 AM

All replies

  • User1031775717 posted

    As far as I know it would be the postHandlingAction="ThrowNewException" which determines if true or false is returned


    Other options are "None" or "NotifyRethrow"

    Tuesday, February 21, 2012 8:48 PM