cancel
Showing results for 
Search instead for 
Did you mean: 

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

silvi
Champ in-the-making
Champ in-the-making
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?
3 REPLIES 3

silvi
Champ in-the-making
Champ in-the-making
Not sure why the xml cannot be seen here in the post so please check the txt file in the attachment for more information about the question.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Silvi,

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?

Current implementation do not surround listener call by try catch (BpmError) block. That's the reason why it behaves in this way. May be you have found good place for improvement.

Regards
Martin

silvi
Champ in-the-making
Champ in-the-making
Thanks Martin for your quick reply 🙂 so i know what we have to do next …

Regards,
Silvi