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
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.