Error boundary event did not work

cancel
Showing results for 
Search instead for 
Did you mean: 
guyuecanhui
Member II

Error boundary event did not work

Hi,

I'm trying to handle exceptions from a subprocess with a parallel gateway. I expect the subprocess to run into and endEvent with failure, but it didn't. The process is defined as follows:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:activiti="http://activiti.org/bpmn"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             targetNamespace="Examples"
             xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL
             http://www.omg.org/spec/BPMN/2.0/20100501/BPMN20.xsd">
    <process id="ErrSubParallelTest" name="Parallel wait">
        <documentation>Asynchorous nonexclusive parallel process</documentation>
        <startEvent id="start" name="Test Start"/>
        <subProcess id="subprocess" name="Sub Process">
            <startEvent id="startSub" name="Sub Process Start"/>
            <parallelGateway id="fork" name="Parallel Gateway Fork"/>
            <scriptTask id="wait1" name="wait 1" scriptFormat="groovy" activiti:async="true" activiti:exclusive="false">
                <script>
                    long a = 1/0;
                </script>
            </scriptTask>
            <scriptTask id="wait2" name="wait 2" scriptFormat="groovy" activiti:async="true" activiti:exclusive="false">
                <script>
                    out:println "wait thread 2 start";
                    sleep(300);
                    out:println "wait thread 2 continue";
                    sleep(200);
                    out:println "wait thread 2 end";
                </script>
            </scriptTask>
            <scriptTask id="wait3" name="wait 3" scriptFormat="groovy" activiti:async="true" activiti:exclusive="false">
                <script>
                    out:println "wait thread 3 start";
                    sleep(200);
                    out:println "wait thread 3 continue";
                    sleep(200);
                    out:println "wait thread 3 end";
                </script>
            </scriptTask>
            <receiveTask id="view1" name="rcv1" activiti:async="true" activiti:exclusive="false"/>
            <receiveTask id="view2" name="rcv2" activiti:async="true" activiti:exclusive="false"/>
            <receiveTask id="view3" name="rcv3" activiti:async="true" activiti:exclusive="false"/>
            <parallelGateway id="join" name="Parallel Gateway Join"/>
            <endEvent id="endSub" name="Sub process end"/>

            <sequenceFlow id="flow1" name="" sourceRef="startSub" targetRef="fork"/>
            <sequenceFlow id="flow2" name="" sourceRef="fork" targetRef="wait1"/>
            <sequenceFlow id="flow3" name="" sourceRef="fork" targetRef="wait2"/>
            <sequenceFlow id="flow4" name="" sourceRef="fork" targetRef="wait3"/>
            <sequenceFlow id="flow5" name="" sourceRef="wait1" targetRef="view1"/>
            <sequenceFlow id="flow6" name="" sourceRef="wait2" targetRef="view2"/>
            <sequenceFlow id="flow7" name="" sourceRef="wait3" targetRef="view3"/>
            <sequenceFlow id="flow8" name="" sourceRef="view1" targetRef="join"/>
            <sequenceFlow id="flow9" name="" sourceRef="view2" targetRef="join"/>
            <sequenceFlow id="flow10" name="" sourceRef="view3" targetRef="join"/>
            <sequenceFlow id="flow11" name="" sourceRef="join" targetRef="endSub"/>
        </subProcess>
        <boundaryEvent id="catchError" attachedToRef="subprocess">
            <errorEventDefinition errorRef="AIA_ERROR_99"/>
        </boundaryEvent>
        <endEvent id="end" name="End test">
            <terminateEventDefinition></terminateEventDefinition>
        </endEvent>

        <sequenceFlow id="flow12" name="" sourceRef="start" targetRef="subprocess"/>
        <sequenceFlow id="flow13" name="" sourceRef="catchError" targetRef="end"/>
    </process>
</definitions>

To catch the exception thrown from wait1, I implemented an event listener:

public class GlobalEventListener implements ActivitiEventListener {
    @Override
    public void onEvent(ActivitiEvent event) {
        ActivitiEventType type = event.getType();
if (type.equals(ActivitiEventType.JOB_EXECUTION_FAILURE)) {
            System.out.println("Get Job execution failure.");
throw new BpmnError("AIA_ERROR_99");
        }
    }

    @Override
    public boolean isFailOnException() {
return false;
    }
}

Then I deployed the process, and started it. The flow didn't terminate when JOB_EXCUTION_FAILURE was captured. Instead, wait1 retried for three times before it suspended.

Did I make things wrong? Any help will be appreciated!

1 Reply
jearles
Established Member II

Re: Error boundary event did not work

Calvin,

I see in your 'wait1' scriptTask:

<scriptTask id="wait1" name="wait 1" scriptFormat="groovy" activiti:async="true" activiti:exclusive="false">
   <script>
      long a = 1/0;
   </script>
</scriptTask>

You're dividing by zero, which in Javascript doesn't cause any errors as it is then concluded as 'Infinity' - however, in Groovy and Java, this same code snippet would conclude with an "java.lang.ArithmeticException: / by zero" error. I imagine that's your intention, and you're trying to catch this exception, correct?

However, as stated in the User Guide, the behavior you're describing is intended:

  • "Activiti, in its default configuration, reruns a job 3 times in case of any exception in execution of a job. This holds also for asynchronous task jobs."

-JEarles
bp3