title: Throw an exception from inside javascript
body: <p>I have a project that uses Activiti engine.
  It support running scripts using Nashorn. 
  I have no problem running this code in either script tasks or in task listeners.
  But when using execution listeners I have issues.</p>
  
  <p>In my script I want to throw an error that should be caught by the java code.
  For example:</p>
  
  <pre><code>    throw new Error("this is an error");
  </code></pre>
  
  <p>But I get an error:</p>
  
  <pre><code>    problem evaluating script: Error: this is an error in scripts/error.js at line number 8 at column number 1
  </code></pre>
  
  <p>I have also tried this initially:</p>
  
  <pre><code>    var BpmnError = Java.type(org.activiti.engine.delegate.BpmnError');
      throw new BpmnError("BusinessExeptionOccured","a Message");
  </code></pre>
  
  <p>In this case no error is caught as if the throw never happened.</p>
  
  <p>In the Activiti documentation it states:</p>
  
  <pre><code>  As of Activiti 5.9, it is possible to throw BPMN Errors from user code inside Service Tasks or Script Tasks. In order to do this, a special ActivitiException called BpmnError can be thrown in JavaDelegates or scripts
  </code></pre>
  
  <p>I have not been able find any example of how this can be done.</p>
  
  <p>I have also not seen any examples of JavaScript code that can throw a jdk.nashorn.internal.runtime.ECMAException
  A comment in the opendJDK ECMAException states:</p>
  
  <pre><code>Exception used to implement ECMAScript "throw" from scripts. 
  </code></pre>
  
  <p>Any help with this will be appreciated.</p>