创建了一个简单的类来测试 PostSharp 中的 OnExceptionAspect。
[Serializable]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
public class ExceptionSwallower : OnExceptionAspect
{
public override void OnException(MethodExecutionEventArgs eventArgs)
{
eventArgs.FlowBehavior = FlowBehavior.Return;
base.OnException(eventArgs);
}
}
将属性添加到方法
[ExceptionSwallower]
public void SomeMethod()
{
throw new Exception();
}
并调用它。
然而,异常并没有真正被吞掉,这看起来很奇怪。
我还没有找到任何类似的问题,所以我希望有一些小事情我没有做对。任何人?