We have several processes that make use of BpmnError in case of business exceptions. In most cases, those errors are handeled by e.g. boundary events, in other cases, the process instance terminates.
Now we are trying to build a generic solution to catch those cases and do some post-processing of the process instance.
First we tried to use a BpmnParseListener to add an Execution Listener to the ProcessDefinition. Unfortunately the listener ist not called (did we miss something?) and if it was called - how do we find out that an BpmnError was thrown?
Second idea was to build an event subprocesses in the diagram, which is triggeres by an error event and stores errorCode and errorMessage in process variables. This works fine and we can access the error information.
Now we would like to “inject” this subprocess in each of our diagrams.
We tried BpmnParseListener again, but cannot find out how to add the definition of the ModelApi using in the listener method?
void parseProcess(Element processElement, ProcessDefinitionEntity processDefinition) {
BpmnModelInstance subProcess = Bpmn.createProcess()
.eventSubProcess("ExceptionHandlingSubProcess")
.startEvent("ExceptionCatched")
.error()
.serviceTask("ExceptionHandler").camundaDelegateExpression("${exceptionHandler}")
.endEvent("ExceptionHandled")
.subProcessDone().done();
// TODO: add me!?
}
Of course any ideas for a better solution are welcome aswell :-).