小编gre*_*007的帖子

使用统一拦截来解决异常处理作为横切关注点

我创建了自己的行为,如下所示:

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块.谁能澄清为什么?我并不是真的想要解决问题,因为有许多方法可以处理异常,更多的是我不明白发生了什么,我想.

c# unity-interception

5
推荐指数
1
解决办法
4319
查看次数

标签 统计

c# ×1

unity-interception ×1