Transaction transaction = (environment!=null ? environment.get(Transaction.class) : null);
if (transaction!=null) {
log.trace("registering exception handler to "+transaction);
CommandService commandService = environment.get(CommandService.class);
if (commandService==null) {
throw new JbpmException("environment doesn't have a command service for registering transactional exception handler", exception);
}
ExceptionHandlerSynchronization exceptionHandlerSynchronization = new ExceptionHandlerSynchronization(
this, execution,
exception,
commandService
);
// registration of the synchronization is delegated to the AfterTxCompletionListener
// to avoid a dependency on class Synchronization
exceptionHandlerSynchronization.register(transaction);
log.trace("registering exception handler to "+transaction);
throw new JbpmException("transaction exception handler registered handler after transaction completed. make sure this transaction is rolled back", exception);
} else {
throw new JbpmException("no transaction present in the environment for transactional exception handler", exception);
}
} else {
executeHandler(execution, exception);
}
}