# Throwing BPMN Error in script task - javascript

**URL:** <https://forum.camunda.io/t/throwing-bpmn-error-in-script-task-javascript/17722>\
**Category:** Discussion & Questions\
**Tags:** process-engine\
**Created:** [February 2, 2020, 4:35pm UTC](https://forum.camunda.io/t/throwing-bpmn-error-in-script-task-javascript/17722 "2020-02-02T16:35:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtvspec](https://forum.camunda.io/letter_avatar_proxy/v4/letter/m/c37758/32.png) [@mtvspec](https://forum.camunda.io/u/mtvspec)\
**Post date:** [February 2, 2020, 4:35pm UTC](https://forum.camunda.io/t/throwing-bpmn-error-in-script-task-javascript/17722/1 "2020-02-02T16:35:35Z")

</div>

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

Script:

```js
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:

```auto
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](https://forum.camunda.io/uploads/short-url/lnG1io05f6ItY4xiXNDutgSqCvI.bpmn) (6.6 KB)

---

<div class="post-metadata">

**Author:** ![sdibernardo](https://forum.camunda.io/user_avatar/forum.camunda.io/sdibernardo/32/8281_2.png) [@sdibernardo](https://forum.camunda.io/u/sdibernardo)\
**Post date:** [February 3, 2020, 8:19am UTC](https://forum.camunda.io/t/throwing-bpmn-error-in-script-task-javascript/17722/2 "2020-02-03T08:19:44Z")

</div>

@StephenOTT posted something on medium a while ago regarding this topic: [Link](https://medium.com/@stephenrussett/throwing-bpmn-errors-with-javascript-in-camunda-c678f4b7d9ff). 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 👍

---

<div class="post-metadata">

**Author:** ![Ingo\_Richtsmeier](https://forum.camunda.io/user_avatar/forum.camunda.io/ingo_richtsmeier/32/25968_2.png) [@Ingo\_Richtsmeier](https://forum.camunda.io/u/Ingo_Richtsmeier)\
**Post date:** [February 3, 2020, 10:53am UTC](https://forum.camunda.io/t/throwing-bpmn-error-in-script-task-javascript/17722/3 "2020-02-03T10:53:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mtvspec](https://forum.camunda.io/letter_avatar_proxy/v4/letter/m/c37758/32.png) [@mtvspec](https://forum.camunda.io/u/mtvspec)\
**Post date:** [February 3, 2020, 6:53pm UTC](https://forum.camunda.io/t/throwing-bpmn-error-in-script-task-javascript/17722/4 "2020-02-03T18:53:11Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![system](https://forum.camunda.io/uploads/default/original/3X/5/8/58d50142eacca605d35cb1ef9e6b86ae85f49436.png) [@system](https://forum.camunda.io/u/system)\
**Post date:** [January 30, 2024, 12:11pm UTC](https://forum.camunda.io/t/throwing-bpmn-error-in-script-task-javascript/17722/6 "2024-01-30T12:11:09Z")

</div>

Closed on January 30, 2024, 12:11pm UTC


