During Drools execution, if I get any exception in any rule, the rule engine should skip the specific rule and execute rest of the rules in knowledge base.
1 Answers
If the RHS of a rule may trigger an exception, it is up to the rule author to write the RHS in such a way to handle the exception.
This is also because the exception may occur in any point of the RHS body; the remaining statements of the RHS might miss the chance to update the working memory with a new state following the operations which may have triggered the exception, thus leaving the working memory in an inconsistent state from a business/domain/knowledge point of view, as in the following example:
rule "Process order"
when
$o : Order()
then
processSomeOrder($o); // some exception might occur here
...
delete($o);
end
Without exception handling this may lead to processing the order multiple times always ending up with the exception over and over; depending on the business/domain/knowledge point of view, the rule might be revised as follows:
rule "Process order"
when
$o : Order()
then
try {
processSomeOrder($o); // some exception might occur here
} catch(Exception e) {
forwardOrderToHumanForManualProcessing($o, e);
}
...
delete($o);
end
In this example is up to the domain/business design to decide how to handle the potential exception occuring during standard processing, and in the case of exception take another business operation. In any case the state of the WM is managed consistently.

- 2,178
- 2
- 15
- 23