Reputation: 25
When I use Unity 2.0 to handle exception, I got some problem, like below:
public class TraceBehavior : IInterceptionBehavior
{
public IEnumerable<Type> GetRequiredInterfaces()
{
return Type.EmptyTypes;
}
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
Console.WriteLine(string.Format("Invoke method:{0}",input.MethodBase.ToString()));
IMethodReturn result = getNext()(input, getNext);
if (result.Exception == null)
{
Console.WriteLine("Invoke successful!");
}
else
{
Console.WriteLine(string.Format("Invoke faild, error: {0}", result.Exception.Message));
result.Exception = null;
}
return result;
}
public bool WillExecute { get { return true; } }
}
I have set result.Exception=null (it's meaning that I have resolved the exception and need not throw again.)
However,it throw a exception to me.
Upvotes: 2
Views: 558
Reputation: 30411
That's not how it works. Don't set result.Exception, instead return input.CreateMethodReturn(newReturnValues).
Upvotes: 3