// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using Vajhoej.StaticWeaver; namespace MyStuff { // aspect [Aspect] public class Error { // pointcut: // any return type, class MyStuff.IntMath, any method name, any arguments // any return type, class MyStuff.DoubleMath, any method name, any arguments [Pointcut(Signature="* MyStuff.IntMath::*(*) || * MyStuff.DoubleMath::*(*)")] public static void MathError() { } // advice: // at exception [AtExceptionAdvice(Pointcut="MathError")] public static void Enter(MethodJoinpoint mjp) { Console.WriteLine("AOP> Exception in math calculation: " + mjp.CaugthException.Message); Environment.Exit(0); } } }