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?

user1761377
  • 73
  • 1
  • 6

1 Answers1

1

The general strategies for exception handling apply here as well: just consider a consequence as being a static method that is being called due to the fireUntilHalt.

If the exception should or must be handled in the context of the RHS code, you'll have to use a try-catch statement. Otherwise, the exception is propagated and the remainder of the RHS code will not be executed. (This may include the omission of some essential statement such as a modify or insert or retract, which may affect the progress of the session.)

If you catch the exception org.drools.runtime.rule.ConsequenceException in a try around the fireUntilHalt, you can call fireUntilHalt again. The remarks from the previous paragraph apply here as well.

How you log an exception is completely up to you, but inserting Exception objects as facts (and writing rules to reason over them?) seems rather unconventional.

laune
  • 31,114
  • 3
  • 29
  • 42