AnsweredAssumed Answered

How to catch an error by a boundary error event thrown by a service task listener?

Question asked by silvi on Jun 20, 2014
Latest reply on Jun 20, 2014 by silvi
Hi
I have got a service task that uses the following delegate
public class ThrowBpmnErrorDelegate implements JavaDelegate {

  public void execute(DelegateExecution execution) throws Exception {
    try {
      executeBusinessLogic();
    } catch (BusinessException e) {
      throw new BpmnError("SomeExceptionOccurred");
    }
  }

}
and my xml for catching the error is
<serviceTask id="servicetask4" name="My Service Task" activiti:class="aaa.bbb.process.delegates.ThrowBpmnErrorDelegate"></serviceTask>
<boundaryEvent id="boundaryerror1" name="Error" attachedToRef="servicetask4">
      <errorEventDefinition errorRef="SomeExceptionOccurred "> </errorEventDefinition>
    </boundaryEvent>

This works perfectly ok and the error is caught by the boundary error event.
BUT if I use a listener that does the same thing (i.e. throws a BpmnError) as below
public class ThrowBpmnErrorListener implements ExecutionListener
{
    public void notify(DelegateExecution execution) throws Exception
    {       
       try {
      executeBusinessLogic();
    } catch (BusinessException e) {
      throw new BpmnError("SomeExceptionOccurred");
    }
  }
}
and my xml for catching the error is
<serviceTask id="servicetask4" name="My Service Task" activiti:class="aaa.bbb.process.delegates.SomeDelegateNotThrowingError">
      <extensionElements>
        <activiti:executionListener event="start" class="aaa.bbb.process.listeners.ThrowBpmnErrorListener">
</activiti:executionListener>
      </extensionElements>
    </serviceTask>
<boundaryEvent id="boundaryerror1" name="Error" attachedToRef="servicetask4">
      <errorEventDefinition errorRef=" SomeExceptionOccurred"> </errorEventDefinition>
    </boundaryEvent>

Then this does not work. So my question is there any limitation that a boundary error event cannot catch an error from a service task if the error is thrown inside a listener used in the service task?

Outcomes