// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package traditional;

// aspect
aspect Error2 {
    // pointcut:
    //   public visibility, any return type, class traditional.IntMath, any method name, any arguments
    //   public visibility, any return type, class traditional.DoubleMath, any method name, any arguments
    pointcut matherror() : call(public * traditional.IntMath.*(..)) || call(public * traditional.DoubleMath.*(..));
    // advice:
    //   around
    Object around() : matherror() {
        Object res = null;
        try {
            res = proceed();
        } catch(Throwable e) {
            System.out.println("AOP> Exception in math calculation: " + e.getMessage());
            System.exit(0);
        }
        return res;
    }
}
