Ich habe den folgenden Code:Wie wird der Methodenfluss mit dem OnException-Aspekt (PostSharp) fortgesetzt?
[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");
}
Verwendung FlowBehavior.Continue endet divide() und kehrt zu der main() Methode.
Ähm, Ihre Methode ist mit '[OnExceptionAspect]' dekoriert, so dass es das Standard-Verhalten von PostSharp 'OnExceptionAspect' ausführt, das nichts ist. Sie müssen es mit '[ExceptionAspectHandler]' dekorieren, damit Ihr Code funktioniert – Shevek