How to pass data with an error event?

Hello,

if an activity throws a BpmnError, then an error boundary event can be attached to the activity to “catch” it and let the process continue at a specific path. Along with the error event, two data elements are passed: the error code and the error message.

But what if I want to pass more data with the error event? E.g. some complex java object? How would I do that?

My only idea so far has been the following: Just before throwing a BpmnError in the activity’s code, I’d set the data to pass along with the error as a process variable, e.g. via execution.setVariable("myErrorInfo", errorData). Then the steps on the path starting with the error boundary event will be able to access that data via execution.getVariable("myErrorInfo").

Is this the recommended way? How do you do that?

Thank you for your insights.

Hey @fml2,

I did the following and I also recommend it. Add a Error Message Variable to your Error Boundary Event configuration properties like this.

Then from your activity code to the following.

throw new BpmnError("boundaryErrorCode", "Message that will turn into variable and will be held by the Error Message Variable value as a process variable");

Here is the result when I check my variables in my process instance.

Regards,

2 Likes

Hello @patozgg,

thank you for your reply, but it does not answer my question which was

Hey @fml2,

As per the docs it is only possible to pass a String. I believe such String is meant to indicate a simple reasoning behind the triggering of such error event. Anything else besides a simple String must be set as a process variable as per your recommended approach.

Regards,