AnsweredAssumed Answered

How to do exception handling in Activiti v6.0.0

Question asked by nami on Apr 23, 2018
Latest reply on Apr 25, 2018 by hari

Mauricio Salatino

 

Hi I am new to Activiti Framework, Can someone please give information on how can we do exception handling in activiti v6.0.0 . Please attach a sample bpmn xml file with exception as a service task, and also the exception class(java code) if possible.

 

I found this while searching for info on exception handling, but this code doesn't work for v6.0.0. It only works for v5.19.0.

 

Exception Class:

 

import org.activiti.engine.impl.pvm.PvmTransition;
import org.activiti.engine.impl.pvm.delegate.ActivityBehavior;
import org.activiti.engine.impl.pvm.delegate.ActivityExecution;


public class ThrowsExceptionBehavior implements ActivityBehavior {

private static final long serialVersionUID = 1L;

private org.activiti.engine.impl.el.FixedValue text;

private org.activiti.engine.impl.el.Expression exp;

public void execute(ActivityExecution execution) throws Exception {
//String text = (String) execution.getVariable("text");

PvmTransition transition = null;
try {
System.out.println("In ThrowsExceptionBehavior class: "+ text);
//throw new Exception("Activiti Exception");
transition = execution.getActivity().findOutgoingTransition("no-exception");
} catch (Exception e) {
transition = execution.getActivity().findOutgoingTransition("exception");
}
execution.take(transition);
}
}

 

BPMN File :

 

<startEvent id="startevent1" name="Start"></startEvent>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetaskCustom"></sequenceFlow>
<serviceTask id="servicetaskCustom" name="test" activiti:class = "@ThrowsExceptionBehavior" >
<extensionElements>
<activiti:field name="text" stringValue="Hello World" />
</extensionElements>
</serviceTask>
<sequenceFlow id="no-exception" sourceRef="servicetaskCustom" targetRef="endevent1" />
<sequenceFlow id="exception" sourceRef="servicetaskCustom" targetRef="fixException" />

<serviceTask id="fixException" name="print" activiti:expression="#{result.print()}"></serviceTask>
<sequenceFlow id="exceptionOccurred" sourceRef="fixException" targetRef="endevent1" />

Outcomes