I cannot understand why advice @After is applied instead of @AfterThrowing in this situation:
@Pointcut("execution(* componentB.Bye.run())")
public void newThread(){
}
@After("newThread()")
public void cokolwiek2(JoinPoint joinPoint){
report(joinPoint);
}
@AfterThrowing(pointcut="newThread()",throwing="e")
public void itsAFoo(JoinPoint joinPoint, RemoteException e) {
logger.error(joinPoint.getSignature().toLongString() + " exception here!");
}
I am sure that exception is thrown in:
public String greeting(String c) throws RemoteException,
InterruptedException {
throw new RemoteException();
//return "Good morning!";
}
But there is no log with exception here!
The pointcut
execution(* componentB.Bye.run())doesn’t cover methodpublic String greeting(String c).The difference between
@Afterand@AfterThrowingis that@AfterThrowingis called only when an exception occurred, while@Afteris called either if an exception was thrown or the method returned successfully. So if there is an exception and you have both advises, both of them will be executed.