// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; namespace NewStuff { // aspect public aspect Error2 { // pointcut: // any return type, class NewStuff.IntMath, any method name, any arguments // any return type, class NewStuff.DoubleMath, any method name, any arguments pointcut MathError() : execution(public static any NewStuff.IntMath.any(..)) || execution(public static any NewStuff.DoubleMath.any(..)); // advice: // around object around() : MathError() && aroundptr(adp) { try { return adp.InnerInvoke(); } catch(Exception e) { Console.WriteLine("AOP> Exception in math calculation: " + ((Exception)thisJoinPoint.Args[0]).Message); Environment.Exit(0); return null; } } } }