ExceptionPolicy.HandleException .. probelm with the new overloaded method

Topics: Exception Handling Application Block
Mar 25, 2008 at 5:11 PM
the ExceptionPolicy.HandleException method accept an output parameter that i think it supposed to return back with a reference to the exception that is supposed to be re-thrown ...
i'm trying to use this method like that

Exception NewException;
bool rethrow = ExceptionPolicy.HandleException(ex, "Exception Policy",out NewException);
if (rethrow)
{
throw NewException;
}

i configured the policy to Wrap the exception .. so i think it is supposed that the NewException variable to be the new rapped exception ....

the problem is that it always return as NULL.
i tried to use replace handler rather wrap handler ... but the same result .. the output parameter always return as null

any idea please
Apr 22, 2008 at 4:34 PM
ExceptionPolicy.HandleException(Exception ex, string policyName) returns if true or false to rethrow / throw new exception. you don't need the o/p parameter as u wrote:

DavidsMaguire wrote:

Exception NewException;
bool rethrow = ExceptionPolicy.HandleException(ex, "Exception Policy",out NewException);
if (rethrow)
{
throw NewException;
}


all you need is to configure the PostHandlingAction of the Exception you are trying to handle, say System.Exception, to ThrowNewException , as in the Enterprise Library Exception Handling Quick Start Sample, and write the following in replace of your code

try
{
// Code causing Exception
}
catch(Exception ex)
{
try
{
if (ExceptionPolicy.HandleException(ex, "Wrap Policy"))
throw;
}
catch (Exception ex2)
{
// Do whatever you want with the wrapped exception
MessageBox.Show(ex2.Message);
}
}