Tengo el siguiente código:¿Cómo continuar el flujo del método usando el aspecto 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");
}
Usando FlowBehavior.Continue termina dividir() y vuelve al método main().
Um, su método está decorado con '[OnExceptionAspect]' por lo que hará el comportamiento predeterminado PostSharp 'OnExceptionAspect' que no es nada. Debes decorarlo con '[ExceptionAspectHandler]' para que funcione tu código – Shevek