# Throw BpmnError exception from javascript

**URL:** <https://forum.flowable.org/t/throw-bpmnerror-exception-from-javascript/1253>\
**Category:** Flowable Engine\
**Created:** [November 23, 2017, 2:40pm UTC](https://forum.flowable.org/t/throw-bpmnerror-exception-from-javascript/1253 "2017-11-23T14:40:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jespriu](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@jespriu](https://forum.flowable.org/u/jespriu)\
**Post date:** [November 23, 2017, 2:40pm UTC](https://forum.flowable.org/t/throw-bpmnerror-exception-from-javascript/1253/1 "2017-11-23T14:40:04Z")

</div>

Hi all,  
I would like to thow from javascript (or groovy) scripts inside Script Task or Execution listener to be captured by a Error Boundary, but I’m not succedding in find the correct syntax:

As I’m using Flowable 6.1.2 I trie to adapt the next code I find in some GIT examples:

```
var JvmUtil = Packages.org.flowable.engine.common.impl.util.JvmUtil; 
var BpmnError = Packages.org.flowable.engine.delegate.BpmnError; 
if (JvmUtil.isJDK8()) 
{ 
 throw new BpmnError("Error"); 
} 
else 
{ 
 var Context = Packages.sun.org.mozilla.javascript.internal.Context; 
 Context.throwAsScriptRuntimeEx(new org.flowable.engine.delegate.BpmnError("Error")); 
} 

```

But it keeps complaining the Process execution of javascript error:

```
problem evaluating script: org.flowable.engine.delegate.BpmnError: in <eval> at line number 7 at column number 4

```

Any ideas? May you confirm I select the correct classes in Flowable 6.1.2?

Best regards.

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [November 25, 2017, 12:41pm UTC](https://forum.flowable.org/t/throw-bpmnerror-exception-from-javascript/1253/2 "2017-11-25T12:41:51Z")

</div>

The code looks ok, it’s similar to here: [https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/error/BoundaryErrorEventTest.testCatchErrorOnJavaScriptScriptTask.bpmn20.xml#L14](https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/error/BoundaryErrorEventTest.testCatchErrorOnJavaScriptScriptTask.bpmn20.xml#L14)

What JVM version are you running this on?

---

<div class="post-metadata">

**Author:** ![jespriu](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@jespriu](https://forum.flowable.org/u/jespriu)\
**Post date:** [November 25, 2017, 5:57pm UTC](https://forum.flowable.org/t/throw-bpmnerror-exception-from-javascript/1253/3 "2017-11-25T17:57:00Z")

</div>

Thanks for the response!  
I’m running jdk1.8.0\_141 and flowable in a Tomcat 9.0.0.M26

I reduced to minimum the code, and it’s failing the third sentence:

```
  var BpmnError=Packages.org.flowable.engine.delegate.BpmnError;
  ex=new org.flowable.engine.delegate.BpmnError("Error");
  throw ex;

```

The error is:

```
  {
     "message": "Internal server error",
     "exception": "problem evaluating script: org.flowable.engine.delegate.BpmnError: in <eval> at line number 3 at column 
 number 0"
  }

```

The only difference I’m thinking is that I’m using this Javascript code inside a execution listener of “end” event with the builtin delegate: org.flowable.engine.impl.bpmn.listener.ScriptExecutionListener  
I obviously pass the two param (language=JavaScript and script with previous sentence).

Thanks.

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [December 13, 2017, 9:09am UTC](https://forum.flowable.org/t/throw-bpmnerror-exception-from-javascript/1253/4 "2017-12-13T09:09:56Z")

</div>

It should be the same, using it in a listener/script task goes to the same logic.  
Just to make sure: can you try with another jvm version?  
Can you execute the unit test (BoundaryErrorEventTest.testCatchErrorOnJavaScriptScriptTask.bpmn20.xml) and see what it does for your on your environment?
