Tôi có đoạn mã sau:Làm thế nào để tiếp tục luồng phương pháp sử dụng khía cạnh OnException (PostSharp)?
[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");
}
Sử dụng FlowBehavior.Continue kết thúc divide() và trở về phương thức main().
Um, phương pháp của bạn được trang trí bằng '[OnExceptionAspect]' do đó nó sẽ thực hiện hành vi PostSharp 'OnExceptionAspect' mặc định không có gì. Bạn cần phải trang trí nó bằng '[ExceptionAspectHandler]' để mã của bạn hoạt động – Shevek