Hi,
I am having issue regarding Aspectj exception handling. I have following aspectJ advice which is called when any throwable exception is thrown from the
java code execution.
Advice:
after() throwing (Throwable t): execution(public * *(..)) && within (com.test.TestClass) {
String method = thisJoinPoint.getSignature().getName();
System.err.println("Threw in the method :"+t.getMessage()+". "+method);
calTrans.setStatus(t);
}
Above advice will print the exception when any exception is thrown from public method of TestClass. Hence, following code is working for the following public method of TestClass:
1. Explicit Exception handling
public void callMethod() {
int a =1/0;
}
But when method has try and catch block inside it and method is not throwing exception explicitly at that time above advice will not work. So, following code is not taken care by above AspectJ advice.
2. Inside Exception:
public void callMethod() {
try{
int a =1/0;
}catch(Throwable th){
System.out.println("I am at catch ");
}
}
So, can anybody please suggest AspectJ advice which will be called when any method has try and catch block. and when that catch_block catches the exception , it should call AspectJ advice.
Thanks in advance.
Thanks,
Rajan