In a service class , I publish an event synchronously using bus.post(event).now() , the corresponding event handler which is annotated with @handler executes successfully. However if I throw an Exception inside the event handler , the thrown exception cannot be caught and org.springframework.transaction.TransactionSystemException is caught instead.
Please refer the following codes for more detail :
@Service
@Transactional
public class Service{
public void someAction(){
/**Do some business logic ***/
bus.post(anEvent).now();
}
}
@Service
@Transactional
public class SomeEventHandler{
@Handler
public void handleWithdrawnEvent(Event event) {
/**The event handler code***/
throws new ApplicationException("Oops , some error happens");
}
}
if service.someAction() executes , my custom ApplicationException cannot be caught .Instead the following exception is caught instead:
org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
In a service class , I publish an event synchronously using
bus.post(event).now(), the corresponding event handler which is annotated with @handler executes successfully. However if I throw an Exception inside the event handler , the thrown exception cannot be caught andorg.springframework.transaction.TransactionSystemExceptionis caught instead.Please refer the following codes for more detail :
if
service.someAction()executes , my customApplicationExceptioncannot be caught .Instead the following exception is caught instead: