The AfterThrowing advice will be executed when the matched methods of the target object exit with an exception. This is also useful when you want to take an action on an exception that occurred during execution of the method. Let's create AfterThrowing advice as follows:
<aop:aspect id="sendMsg" ref="sendMsgAspect"> <aop:after-returning pointcut-ref="hrServiceMethods" returning="retVal" method="sendMessageOnSuccessExit"/> <aop:after-throwing pointcut-ref="hrServiceMethods" method="sendMessageOnErrorExit"/> </aop:aspect>
The sendMessageOnErrorExit advice method will be defined in the sendMessage aspect as follows:
//Advice method on existing of target method with some error / exceptionpublic void sendMessageOnErrorExit(JoinPoint ...