// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using DotNetGuru.AspectDNG.Joinpoints; namespace OldStuff { // aspect public class Error { // advice: // around // pointcut: // any return type, class OldStuff.IntMath, any method name, any arguments // any return type, class OldStuff.DoubleMath, any method name, any arguments [AroundCall("* OldStuff.IntMath::*(*)")] [AroundCall("* OldStuff.DoubleMath::*(*)")] public static object MathError(MethodJoinPoint mjp) { try { return mjp.Proceed(); } catch(Exception e) { Console.WriteLine("AOP> Exception in math calculation: " + e.Message); Environment.Exit(0); return null; } } } }