Throwing a BpmnError in my custom code not being caught by error boundary event

I created a BPMN process, and it has one callActivity. The job of the callActivity (custom service task) is to send an email. I need to resolve recipients of the email, and I do this on the parent process, and then pass that resolved variable into my send email callActivity. To resolve recipients, I’ve implemented custom logic so that I can call a custom method to populate the recipients variable. This custom method is made available to the flowable engine runtime via the spring application context (as a Spring Bean - NOT a JavaDelegate). I use a Spring @configuration class to define a handful of singleton beans.

My custom logic is implemented in a bpmn.xml process document like so: see bottom screenshot.

Notice in the sourceExpression, my bean’s name is email and my custom method is called testBpmnError(). This method throws a BpmnError.

My overall goal here is to implement error handling so that when there are errors in my custom code, I can throw them as BpmnErrors, which can be handled in the bpmn processes via boundary events, and I can do something with those errors in my process.

The problem I am having is that when I throw a BpmnError from my custom logic, it comes back as a FlowableException (with root cause being my BpmnError), and the whole transaction rolls back and stops my process in its tracks. The boundary event does not catch the FlowableException.

Is anyone familiar with error handling exceptions in custom code? Ultimately, I want to propagate my errors and do things with them, not shut down my process and roll back the transaction.

I’m a Flowable newb, so I may be missing some foundational knowledge though I have been combing through docs. Here’s my full bpmn process document for reference:

Hey @chelsea.reynolds.ok,

As you are explaining this, things should work. Can you perhaps share a minimal reproducible repo with the code and your model?

By the way in your BPMN process at the end you have an error end event. That error end event will not catch all errors, since that one is not for catching, but it’s for throwing one, i.e. the process ends with throwing a BPMN Error.

Cheers,
Filip

Filip,

Thank you for the fast reply! Here is a public repo where the unit test can replicate the question scenario.

Thanks @chelsea.reynolds.ok,

I think I see the problem now better. You have

<flowable:in sourceExpression="${customBean.testBpmnError(execution, true)}" target="testString"/>

i.e. you are throwing an error in the sourceExpression. This does not work, since this is not a place where we are expecting a business error. You should test it by either throwing that error in the callActivity.bpmn20.xml or use a Service Task with that expression.

Cheers,
Filip