Throw BpmnError exception from javascript

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.

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

What JVM version are you running this on?

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.

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?