Exception mapping does not work

Hi,

I would like to use the exception mapping feature in a service task, but it does not work for me.

I follow exactly the documentation to declare the mapException (see below), in my Java Delegate, I throw an Exception, I attach an ErrorBoundaryEvent to my service task, but the BpmnError is not propagated to it, just the org.activiti.SomeException is thrown an nothing happens. What am I doing wrong?

    <serviceTask id="servicetask1" name="Service Task" activiti:class="...">
  <extensionElements>
    <activiti:mapException
          errorCode="myErrorCode1">org.activiti.SomeException</activiti:mapException>
  </extensionElements>
</serviceTask>

Hi,

Is your SomeException class extending RuntimeException?
Because that’s needed for the map exception logic to work.

Best regards,

Tijs

Yes, I am throwing java.lang.IllegalArgumentException. I am using activiti:expression, could that be the problem?:

    <serviceTask id="my-id" name="..." activiti:async="true" activiti:expression="${myDelegate.myMethod(fileName)}" activiti:resultVariableName="someObject">
        <extensionElements>
            <activiti:mapException errorCode="code-1">java.lang.IllegalArgumentException</activiti:mapException>
        </extensionElements>
    </serviceTask>


    public Object myMethod(String fileName) {
            throw new IllegalArgumentException();
        }


    <boundaryEvent id="boundaryerror1" name="Error" attachedToRef="my-id">
          <errorEventDefinition errorRef="code-1"></errorEventDefinition>
        </boundaryEvent>

<error id="code-1" errorCode="code-1" name="fff"></error>

Hi,

In your first example you were using the class attribute of the service task element and in this new example expression. The map exceptions functionality is currently only supported for the class attribute service tasks. An alternative would be to catch the IllegalArgumentException in your expression bean and throw a BpmnError with the correct error code. This would trigger the boundary error event as well.

Best regards,

Tijs

I understand.
Is there a reason why it’s not supported for expressions?
Most of our service tasks use expressions, so it would be very helpful, if it would be supported (and also support for any Exceptions, not only RuntimeException).

The reason why I would like to attach the exception mapping to the bpmn and not the Java Delegate Bean (by throwing BpmnError) is, that we have different bpmn’s pointing to the same Java Delegate Bean (method), and it should be in the responsibility of the bpmn to decide, if a boundary error event should be triggered or not.

Any chance to add this feature to future flowable releases?

I don’t think there’s a specific reason for it not working with expressions.
So I fully agree it should be added. Will see if I can work on it tomorrow or on Friday so it will be available in the Flowable 6.0.0 release. Are you planning to use Flowable 5? Because then I need to make sure it’s also backported to that version.

Best regards,

Tijs

We plan to use Flowable 5 (at the moment).

Many thanks,
Björn

Hi Björn,

It’s implemented in Flowable 5 and 6 now:

https://github.com/flowable/flowable-engine/commit/03a57e66aa3f5e1e33bc71634f07ac0764391d38

https://github.com/flowable/flowable-engine/commit/e0e56e769ff9345ae5f27fc387279f3582fbaada

Best regards,

Tijs

Are Exceptions (instead of RuntimeExceptions) supported as well?

Our JavaDelegate Beans inject different kind of (OSGi) Service Beans, which declare checked Exceptions, so, if a service throws a specific exception, I can catch it directly in the BPMN.

Hi,

In Flowable 5 we have support for checked Exceptions as well. In Flowable 6 we dropped the checked exceptions support and dropped the throws exception in the execute method of the JavaDelegate interface. So in Flowable 6 only RuntimeExceptions are supported.

Best regards,

Tijs

@tijs sorry for coming back to this issue (we migrated now from 5 to 6), but the missing exception support in expressions (not delegateExpression’s) is some kind of pain of us:

We have many expression like ${myBean.myMethod(..)} , which typically refer to an external Java API, which declares also checked exceptions (which should be catchable in an boundaryerrorevent). If so, I have to rewrite the code to declare everywhere unchecked exceptions or to throw a new BpmnError()

I understand, that you dropped the support for JavaDelegate’s because of removing the exception from the execute method, but for expressions (ServiceTaskExpressionActivityBehavior), it should be fine to support exception !?

I created a PR for this:

1 Like