public class ExceptionCallHandler : ICallHandler
{
// Fields
private ExceptionPolicyImpl exceptionPolicy;
private int order;
public ExceptionCallHandler(string exceptionPolicyName, int order)
{
this.exceptionPolicy = UnityContainerFactory.Instance.Resolve<ExceptionPolicyImpl>(exceptionPolicyName);
this.order = order;
}
// Methods
public ExceptionCallHandler(ExceptionPolicyImpl exceptionPolicy)
{
this.exceptionPolicy = exceptionPolicy;
}
public ExceptionCallHandler(ExceptionPolicyImpl exceptionPolicy, int order)
: this(exceptionPolicy)
{
this.order = order;
}
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (input == null)
{
throw new ArgumentNullException("input");
}
if (getNext == null)
{
throw new ArgumentNullException("getNext");
}
IMethodReturn return2 = getNext()(input, getNext);
if (return2.Exception != null)
{
try
{
if (!this.exceptionPolicy.HandleException(return2.Exception))
{
return2.ReturnValue = null;
return2.Exception = null;
if (input.MethodBase.MemberType == MemberTypes.Method)
{
MethodInfo methodBase = (MethodInfo)input.MethodBase;
if (methodBase.ReturnType != typeof(void))
{
return2.Exception = new InvalidOperationException(Resources.CantSwallowNonVoidReturnMessage);
}
}
}
}
catch (Exception exception)
{
return2.Exception = exception;
}
}
return return2;
}
// Properties
public ExceptionPolicyImpl ExceptionPolicy
{
get
{
return this.exceptionPolicy;
}
}
public int Order
{
get
{
return this.order;
}
set
{
this.order = value;
}
}
}