I see that Guice and Spring use AOP Alliance under the hood for method interceptions, and I've been trying to figure out how to get AOP Alliance to intercept and handle certain exceptions so I don't have to keep writing the same code over and over again inside every catch
block.
But after reviewing the play, it doesn't look like AOP Alliance provides any way to intercept thrown Throwable
s in such a way that the handler/interceptor can do some things (log the exception, etc.) and then determine whether or not to propagate the exception any further or to just recover back to the next line following the line which threw the exception:
HerpDerp hd = null;
if(hd == null)
throw new RuntimeException("Herpyl derp!");
Manny.pacquiao();
I'm looking for an AOP exception handling mechanism that would intercept the RuntimeException
and use business logic to decide whether to keep propagating it or to recover back at the Manny.pacquioa()
call.
- If it is just not possible to do this in Java, please let me know
- Regardless of whether or not its possible to do this in Java, is there a way to intercept thrown Exception with AOP Alliance or do I have to go somewhere else. And if I have to go somewhere else, where? AspectJ?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…