Why test rethow when PostHandlingAction is ThrowNewException?

Apr 13, 2009 at 5:35 PM

I recently stepped through the QuickStart code provided with the Microsoft Enterprise Library 4.1 - October 2008 release and noticed that the ExceptionPolicy.HandleException method actually throws a new exception rather than recommends a rethrow (by returning the value of true) when the specified exception policies has a PostHandlingAction of ThrowNewExeption. So, why would you need to test rethrow? Thank you.

 

 

/// <summary>
/// Demonstrates handling of exceptions coming out of a layer. The policy
/// demonstrated here will show how original exceptions can be wrapped
/// with a different exception before being propagated back out.
/// </summary>
public bool ProcessWithWrap()
{
    try
    {

 

 

        this.ProcessB();

 

    }

 

    catch(Exception ex)
    {
        // Quick Start is configured so that the Wrap Policy will
        // log the exception and then recommend a rethrow.
        bool rethrow = ExceptionPolicy.HandleException(ex, "Wrap Policy");

 

 

        if (rethrow)
        {
             throw
         }
    }

 

 

    return true;

 

}