0

我不明白为什么在这种情况下@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!

4

1 回答 1

2

切入点execution(* componentB.Bye.run())不包括方法public String greeting(String c)

@After和之间的区别在于@AfterThrowing@AfterThrowing在发生异常时@After调用,而在抛出异常或方法成功返回时调用。因此,如果出现异常并且您有两个建议,则它们都将被执行。

于 2012-08-07T14:46:44.813 回答