Throwing BPMN Error in script task - javascript

Hello, cannot understand that the problem with my Script Task implementation.


if (true) {
  execution.setVariable("result", "Error");
  throw new org.camunda.bpm.engine.delegate.BpmnError(“Error Message”);
} else {
  execution.setVariable("result", "Ok");

Error message when starting new process instance:

The process could not be started. :
Expected an operand but found:
error throw new org.camunda.bpm.engine.delegate.BpmnError("Error Message”)

bpmn_error_event_example.bpmn (6.6 KB)

@StephenOTT posted something on medium a while ago regarding this topic: Link. Maybe just copy his part and then replace with yours step by step. Also ensure you chose the right implementation for your script such as Groovy or JavaScript.

Hope that helps :+1:


Hi @mtvspec,

additionally to @sdibernardo’s hint, your quotes around the error message look suspicious.

Maybe you should change them to plain quotes.

Hope this helps, Ingo

1 Like

Yes, you are right. Thank you for help. And mistake was with function signature.
BpmnError("error-code"[, "error-message"]) must be the same as error-code of Error Event.