Exception handling and after advice

前端 未结 1 898
隐瞒了意图╮
隐瞒了意图╮ 2021-01-26 04:26

I am using AOP with spring boot. After some method execution successfully I am using @After advice in AOP to do some data base insertion. There is one case if the method throw a

相关标签:
1条回答
  • 2021-01-26 04:50

    Please read the Spring AOP manual, especially the chapter about advice types. In general it is always a good idea to read a manual before using a new technology. ;-)

    • @After is always executed after a method terminates, no matter if there was an exception or not. More specialised versions only run
    • @AfterThrowing an exception or
    • @AfterReturning regularly. The latter is what you are looking for and it even gives you access to the return value if you like to log it or so.

    None of these advice types will let you handle the exception, though, as I also explain here. You need to use an @Around advice for that.

    0 讨论(0)
提交回复
热议问题