What's the essential difference between the two HandleException() methods of Exception Handling Application Block

Mar 15, 2011 at 7:59 AM

There are two HandleException() method signatures, and I am a bit lost on the intent for these, especially since neither the documentation, intellisense, nor the QuickStart apps intimate any meaningful difference.

Here are the two signatures:

bool HandleException(Exception exceptionToHandle, string policyName); 
 
bool
HandleException(Exception exceptionToHandle, string policyName, out Exception exceptionToThrow); 

All of the examples I have found use the first, as in this example straight out of the XML documentation comments on the actual method:

try 
{ 
   
Foo(); 
} 
catch (Exception e) 
{ 
   
if (ExceptionPolicy.HandleException(e, name)) throw; 
} 

And here, from the same source (the XML doc comments for the method), is an example of using the second:

try 
{ 
   
Foo(); 
} 
catch (Exception e) 
{ 
   
Exception exceptionToThrow; 
   
if (ExceptionPolicy.HandleException(e, name, out exceptionToThrow)) 
   
{ 
     
if(exceptionToThrow == null) 
         
throw; 
     
else 
         
throw exceptionToThrow; 
   
} 
} 

So, my question is, what does using the second one give you that the first does not? 

Mar 15, 2011 at 9:08 AM

Hi,

The second example lets you capture and have an option to throw the exception returned by the Exception Handling block. Take note that when the 'PostHandlingAction' is set to 'ThrowNewException', the HandleException method will return true. Hope this helps.