I have the following:
@AfterReturning("executionOfTrustedAnnotatedMethod()")
public void afterReturningFromTrustedMethodExecution() { ... }
@AfterThrowing(pointcut = "executionOfTrustedAnnotatedMethod()")
public void afterThrowingByExecutionOfTrustedAnnotatedMethod() { ... }
And I observe this behavior, which does not make sense to me:
- If the method captured by this pointcut does not throw an exception, @AfterReturning is executed
- If the method throws an exception, @AfterReturning is only executed if @AfterTrowing exists and is executed first
What I'm trying to execute is to run some code at the end of the method execution, regardless of whether the exception was thrown or not. But now this code is executed twice (if I have both after Returning and afterThrowing) or not at all (if I have it only after Returning) if an exception occurs.
Any suggestions?
Thanks Peter