我有一個使用Activiti引擎的項目。 它支持使用Nashorn運行腳本。 我在腳本任務或任務偵聽器中運行此代碼沒有問題。 但是,當使用執行監聽器我有問題。從內部拋出異常javascript
在我的腳本中,我想拋出一個應該被java代碼捕獲的錯誤。 例如:
throw new Error("this is an error");
但我得到一個錯誤:
problem evaluating script: Error: this is an error in scripts/error.js at line number 8 at column number 1
我自己也嘗試這種最初:
var BpmnError = Java.type(org.activiti.engine.delegate.BpmnError');
throw new BpmnError("BusinessExeptionOccured","a Message");
在這種情況下沒有錯誤捕獲過程如同扔從未發生了。
在它規定的Activiti的文檔:
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
我一直沒能找到如何可以做到這一點的任何例子。
我還沒有看到可以拋出一個jdk.nashorn.internal.runtime.ECMAException 在opendJDK ECMAException註釋的JavaScript代碼的任何實例指出:
Exception used to implement ECMAScript "throw" from scripts.
任何幫助,這可以理解。
我已經更新的問題,並刪除註釋。 –
您是否嘗試了Lian的建議(他還在評論中添加了它,使其很難找到)? 'try {// eval something} catch(ScriptException sx){sx.printStackTrace(); }}' –