Reputation: 24518
Spring docs say:
After advice must be prepared to handle both normal and exception return conditions.
@After("com.xyz.myapp.SystemArchitecture.dataAccessOperation()")
public void doReleaseLock() {
// ...
}
I'm interested in knowing whether dataAccessOperation
completed normally or with an exception. Unfortunately, the above code snippet is in the run for the most useless documentation ever produced. I understand that I can use AfterReturning
and AfterThrowing
separately, or even Around
, but that's not the point. Since After
exists, I should be able to use it.
Upvotes: 1
Views: 1847
Reputation: 67297
What the documentation wants to say is that your @After
advice should do a valid thing no matter whether an exception was thrown or not. It does not mean you can determine it from the advice. If different things should be done,
@AfterReturning
vs. @AfterThrowing
if the control flow is not to be touched and no exception is to be handled by your advices,@Around
advice if you want to actually catch and handle thrown exceptions and/or modify method parameters before call or the return value after the call or skip method execution altogether.Upvotes: 3