AspectJ中@After和@AfterThrowing之间的java差异
我无法理解为什么在这种情况下应用建议@After
而不是@AfterThrowing
:
@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!");
}
我确信会抛出异常:
public String greeting(String c) throws RemoteException,
InterruptedException {
throw new RemoteException();
//return "Good morning!";
}
但是没有带有exception here!
的日志
# 1 楼答案
切入点
execution(* componentB.Bye.run())
不包括方法public String greeting(String c)
@After
和@AfterThrowing
之间的区别在于@AfterThrowing
仅在发生异常时调用,而@After
在抛出异常或方法成功返回时调用。因此,如果有一个例外,并且您有两个建议,那么它们都将被执行