1

I'm not sure what is the correct way of handling exceptions in RHS of rules.

I've a statefullSession (drools version 5.5) that keeps firing until halt gets called i.e.

Runnable firingTask = new Runnable() {
public void run() {
    ksession.fireUntilHalt();
};

taskExecutor.execute(firingTask);

The problem is that some parts of my code that gets called as a part of consequence section might throw an exception. If that happens no furher activations happen

My question is: Is there any correct way how application exception should be propagated back to drools? Or is it that any RHS code has to be run inside try/catch block and these exceptions should be propagated as some additional facts into session?

4

1 回答 1

1

异常处理的一般策略也适用于此处:只需将结果视为由于fireUntilHalt.

如果应该或必须在 RHS 代码的上下文中处理异常,则必须使用 try-catch 语句。否则,将传播异常并且不会执行 RHS 代码的其余部分。(这可能包括一些重要语句的遗漏,例如修改或插入或撤回,这可能会影响会话的进度。)

如果您org.drools.runtime.rule.ConsequenceException在 try 中捕获异常fireUntilHalt,则可以fireUntilHalt再次调用。上一段的评论也适用于此。

如何记录异常完全取决于您,但是将 Exception 对象作为事实插入(并编写规则对其进行推理?)似乎相当不合常规。

于 2015-12-08T13:29:32.770 回答