问题
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