// get the message session from the context
DbMessageService dbMessageSessionImpl = (DbMessageService) jbpmContext.getServices().getMessageService();
MessagingSession messageSession = dbMessageSessionImpl.getMessagingSession();
// get the problematic command message from the exception
Message message = e.message;
// remove the problematic message from the queue
dbMessageSessionImpl.receiveByIdNoWait(message.getId());
message = Message.createCopy(message);
// update the message with the stack trace
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
message.setException(sw.toString());
// update the message with the jbpm-error-queue destination
message.setDestination(errorDestination);
// resend
messageSession.save(message);
} finally {