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

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Around;

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