【发布时间】:2012-05-11 14:14:02
【问题描述】:
我有以下代码:
[Serializable]
class ExceptionAspectHandler:OnExceptionAspect
{
public override void OnException(MethodExecutionArgs args)
{
Console.WriteLine("{0}", args.Exception);
args.FlowBehavior = FlowBehavior.Continue;
}
}
[OnExceptionAspect]
public static void divide()
{
int n = Convert.ToInt32(Console.ReadLine());
var a = 100 / n; //the exception happens here
Console.WriteLine("it should get here");
}
使用 FlowBehavior.Continue 结束 divide() 并返回 main() 方法。
【问题讨论】:
-
嗯,你的方法用
[OnExceptionAspect]装饰,所以它会执行默认的 PostSharpOnExceptionAspect行为,这没什么。你需要用[ExceptionAspectHandler]来装饰它才能让你的代码工作
标签: c# visual-studio exception-handling aop postsharp