# Throw a BPMN error from a script task

**URL:** <https://forum.camunda.io/t/throw-a-bpmn-error-from-a-script-task/23724>\
**Category:** Discussion & Questions\
**Tags:** process-engine\
**Created:** [November 11, 2020, 8:11am UTC](https://forum.camunda.io/t/throw-a-bpmn-error-from-a-script-task/23724 "2020-11-11T08:11:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![smith\_Johnson](https://forum.camunda.io/user_avatar/forum.camunda.io/smith_johnson/32/11858_2.png) [@smith\_Johnson](https://forum.camunda.io/u/smith_Johnson)\
**Post date:** [November 11, 2020, 8:11am UTC](https://forum.camunda.io/t/throw-a-bpmn-error-from-a-script-task/23724/1 "2020-11-11T08:11:06Z")

</div>

Hello all,

I have a script task in a process that I need to implement it with javascript. Following this [link](https://forum.camunda.io/t/throwing-bpmn-error-in-script-task-javascript/17722), I wrote my inline script.

As shown in the image below, **inside my script I fetch the process variable “oldCustomer” (Boolean), and if it is false I throw an error that is caught by a boundary error event.**

```r
var old=execution.getVariable("oldCustomer");
if(old==false){
  throw new org.camunda.bpm.engine.delegate.BpmnError(“NewCustomer”);
}

```

 ![image](https://forum.camunda.io/uploads/default/original/2X/9/9d2250bfdfb79218321986b865a5a8be480fb2b2.png)

However, once I try to start the process from the Tasklis (I set as variable “oldCustomer - Boolean - false”), I receive the following message:

 ![image](https://forum.camunda.io/uploads/default/original/2X/6/67bdae03a396aca1104b753fe7f4361fec38a90e.png)

What am I missing here?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![yogeshrnaik](https://forum.camunda.io/user_avatar/forum.camunda.io/yogeshrnaik/32/11164_2.png) [@yogeshrnaik](https://forum.camunda.io/u/yogeshrnaik)\
**Post date:** [November 11, 2020, 9:37am UTC](https://forum.camunda.io/t/throw-a-bpmn-error-from-a-script-task/23724/2 "2020-11-11T09:37:52Z")

</div>

Try selecting “Async Before” or “Async After” for the Script task.

---

<div class="post-metadata">

**Author:** ![smith\_Johnson](https://forum.camunda.io/user_avatar/forum.camunda.io/smith_johnson/32/11858_2.png) [@smith\_Johnson](https://forum.camunda.io/u/smith_Johnson)\
**Post date:** [November 11, 2020, 12:50pm UTC](https://forum.camunda.io/t/throw-a-bpmn-error-from-a-script-task/23724/3 "2020-11-11T12:50:47Z")

</div>

Thank you so much for your answer, but unfortunately,it didn’t solve the issue

---

<div class="post-metadata">

**Author:** ![aravindhrs](https://forum.camunda.io/user_avatar/forum.camunda.io/aravindhrs/32/32503_2.png) [@aravindhrs](https://forum.camunda.io/u/aravindhrs)\
**Post date:** [November 11, 2020, 12:57pm UTC](https://forum.camunda.io/t/throw-a-bpmn-error-from-a-script-task/23724/4 "2020-11-11T12:57:54Z")

</div>

@smith_Johnson Put `asyncBefore=true` for the interrupting error boundary event

---

<div class="post-metadata">

**Author:** ![jgigliotti](https://forum.camunda.io/user_avatar/forum.camunda.io/jgigliotti/32/10863_2.png) [@jgigliotti](https://forum.camunda.io/u/jgigliotti)\
**Post date:** [November 12, 2020, 1:11pm UTC](https://forum.camunda.io/t/throw-a-bpmn-error-from-a-script-task/23724/5 "2020-11-12T13:11:43Z")

</div>

It looks like your real problem is the quotes around `NewCustomer`

`throw new org.camunda.bpm.engine.delegate.BpmnError(“NewCustomer”);`

This can sometimes happen when pasting text copied out of a rich text area/application. If you retype them as double or single quotes, you won’t have a javascript parsing error anymore

`throw new org.camunda.bpm.engine.delegate.BpmnError("NewCustomer");`

---

<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:44pm UTC](https://forum.camunda.io/t/throw-a-bpmn-error-from-a-script-task/23724/6 "2024-01-30T12:44:52Z")

</div>

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


