I have the following code:
[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");
}
Using FlowBehavior.Continue ends divide() and returns to the main() method.
[OnExceptionAspect]
so it will do the default PostSharpOnExceptionAspect
behaviour which is nothing. You need to decorate it with[ExceptionAspectHandler]
to get your code to work – Batchelder