[rules-users] Exception Handling in the rule consequence

esteban.aliverti at gmail.com esteban.aliverti at gmail.com
Wed Oct 13 12:32:50 EDT 2010


case 1 could be:

*package something*
*
*
*dialect "java" *
*
*
*rule "Some rule"*
*   when*
*      Something()*
*   then*
*      try{*
*         callSomeDangerousLogicHere();*
*      catch (Exception ex){*
*         //manage your exception here*
*      }*
*end*
*
*
The second approach is to write something like this in your java code:

*ksession.insert (someObject);*
*...*
 *
*
*try{*
*   ksession.fireAllRules();*
*} catch (Exception e){  // <-- This will be a ConsequenceException*
*   //manage your exception here*
*}*


Best,

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com


2010/10/13 sumatheja <sumatheja at gmail.com>

> Hi Wolfgang,
> Whats the advantage of option 2 over 1? Can you give sample code for option
> 2??
>
>
> 2010/10/13 Wolfgang Laun <wolfgang.laun at gmail.com>
>
>> In drl, you could use
>>   dialect "java"
>> at outermost level, but one never does, because that's the default.
>>
>> I'd use option (2).
>>
>>
>> -W
>>
>> 2010/10/13 sumatheja <sumatheja at gmail.com>
>>
>>> Hi Wolfgang,
>>>                   I am actually writing all the rules in a .drl and
>>> importing them into a guvnor. I didn't mention the dialect explicitly
>>> anywhere in the code. Is the default dialect MVEL. Is there a way to make
>>> one time declaration of dialect in my case instead of declaring it for all
>>> the rules.
>>>
>>> 2010/10/13 Wolfgang Laun <wolfgang.laun at gmail.com>
>>>
>>> I'd say you are using
>>>>    dialect "mvel"
>>>> There is no try/catch statement in MVEL. You have the options:
>>>>
>>>> (1) Use Java, not MVEL.
>>>>
>>>> (2) Surround the fireAllRules() with try/catch and put it in a loop
>>>> that's terminated
>>>> if there is no exception.
>>>>
>>>> -W
>>>>
>>>>
>>>> 2010/10/13 sumatheja <sumatheja at gmail.com>
>>>>
>>>>> Hi All,
>>>>>         I have a set of rules. After firing the rules if an exception
>>>>> occurs in a rule the following rules are not getting evaluated. So i tried
>>>>> writing a try catch block inside the consequence part of the rule, but then
>>>>> i get an error saying "'unable to build the consequence.[Error:was expecting
>>>>> type: java.lang.Object but found type:null]"
>>>>>
>>>>> Here follows my code
>>>>>
>>>>>
>>>>> *rule 'Test rule'
>>>>> ruleflow-group "Test Ruleflow"
>>>>> no-loop
>>>>>     when
>>>>>         $c:Car()
>>>>>         Driver()
>>>>>
>>>>>     then
>>>>>        try{
>>>>>           $c.getModel()
>>>>>           } catch (Exception Ee) {
>>>>>            System.out.println("caught an exception: "+Ee.toString());
>>>>>           }
>>>>> end*
>>>>>
>>>>> However if i remove the try catch block it buils fine.
>>>>>
>>>>> Can anyone let me know if i'm missing something here.
>>>>>
>>>>> Thanks in advance :)
>>>>> --
>>>>> cheers
>>>>> Sumatheja
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> rules-users mailing list
>>>>> rules-users at lists.jboss.org
>>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> rules-users mailing list
>>>> rules-users at lists.jboss.org
>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>
>>>>
>>>
>>>
>>> --
>>> cheers
>>> Sumatheja Dasararaju
>>>
>>>
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
>
> --
> cheers
> Sumatheja Dasararaju
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20101013/f4fbe3fd/attachment.html 


More information about the rules-users mailing list