Throwing exception in Guvnor (Guided Editor Rule)

▼魔方 西西 提交于 2019-12-13 03:59:55

问题


I'm building a rules project using Guvnor. In one of my DSL, I've the follow "consequence" statement for wrong operations:

[when]Error "{message}"=throw new Exception( "{message}" );

If I use the DSL rule, writing all the rule with DSL sentences, it works perfectly. However, using the Guided Editor, this doesn't work and the validation says anything like that:

[Error: unable to resolve method using strict-mode: org.drools.spi.KnowledgeHelper.throw()] [Near : {... throw new Exception( " ...

Someone knows what I need to do for this works? It's important because my project will be used by non-IT people.

Thanks.


The source code generated by the Guided Editor is very simple:

rule "exception test"
    dialect "mvel"
    when
        eval( true );
    then
        throw new Exception( "error message" );
end

回答1:


The problem is not with the use of DSL sentences but with the use of 'mvel' dialect. It appears that Mvel doesn't like the throw Exception syntax. The solution is to use 'java' dialect instead.

In order to do that, you must add 'java' dialect option in your rule:

Unfortunately, as far as I remember, there is no global setting in Guvnor to use 'java' dialect by default.



来源:https://stackoverflow.com/questions/19194122/throwing-exception-in-guvnor-guided-editor-rule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!