Spring AOP AfterThrowing vs. Around Advice

前端 未结 2 742
悲&欢浪女
悲&欢浪女 2021-02-01 19:48

when trying to implement an Aspect, that is responsible for catching and logging a certain type of error, I initially thought this would be possible using the AfterThrowing advi

2条回答
  •  耶瑟儿~
    2021-02-01 20:26

    The Spring reference doc says:

    "After throwing advice runs when a matched method execution exits by throwing an exception"

    By then it's too late to catch the exception as it has already been thrown and the method has exited. The approach you've taken with the @Around advice is the only way to actually catch the exception and deal with it before the method exits.

提交回复
热议问题