Sometimes there may be situations that throw an exception in the script task activity. Since the Script Task component is not a BPMN-type component, different ways should be followed to manage the error. For example, as we do in the standard, we cannot catch the error with the Boundary event.
For this, the try-catch structure available in many programming languages should be used.
var newVar = execution.getVariable(“newVar”);
var regexResultVar = newVar.match(/[0-9]/g);
execution.setVariable(“regexResultVar”," Regex Not Found !");
var BpmnError = Packages.org.flowable.engine.delegate.BpmnError;
throw new BpmnError(“errName”);
Explanation: In the example above, the bolded fields represent mandatory fields. Other fields that are in try should contain the code block that is likely to cause an error. The field in catch is the field that will work if an error occurs in the field in try.
The trow new BpmnError("errName ") line is a line written so that the boundary event can catch the error again. Thus, we can re-throw a thrown error and use the error content for analysis in our process. For this, the exception we re-throw is entered with the given name in the “Error Reference” field in the boundary event, and it will be tracked on the log side.