Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 22, 2012 12:48 AM by auschucky
Member
292 Points
516 Posts
Dec 09, 2011 12:40 PM|LINK
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>
enterprise handlers library csharp exception
526 Points
137 Posts
Feb 22, 2012 12:48 AM|LINK
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"
vmhatup
Member
292 Points
516 Posts
Why does Enterprise Library ExceptionPolicy.HandleException return true/false?
Dec 09, 2011 12:40 PM|LINK
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; } }<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>enterprise handlers library csharp exception
auschucky
Member
526 Points
137 Posts
Re: Why does Enterprise Library ExceptionPolicy.HandleException return true/false?
Feb 22, 2012 12:48 AM|LINK
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"