我创建了自己的行为,如下所示:
public class BoundaryExceptionHandlingBehavior : IInterceptionBehavior
{
public IEnumerable<Type> GetRequiredInterfaces()
{
return Type.EmptyTypes;
}
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
try
{
return getNext()(input, getNext);
}
catch (Exception ex)
{
return null; //this would be something else...
}
}
public bool WillExecute
{
get { return true; }
}
}
Run Code Online (Sandbox Code Playgroud)
我已正确设置它,以便我的行为按预期命中.但是,如果在任何getNext()中发生任何异常,它都不会触及我的catch块.谁能澄清为什么?我并不是真的想要解决问题,因为有许多方法可以处理异常,更多的是我不明白发生了什么,我想.