Recommendation on handling individual rules' exception

60 views
Skip to first unread message

Leo Lin

unread,
May 16, 2024, 3:16:18 PM5/16/24
to Drools Usage
Hi groups,
I'm looking for suggestion on handling exception when executing a set of rules.
We usually have 20+ rules in one session. What happened was that if one rule failed, the following rules won't be executed as well. Common failures are null pointer error on accessing fields or network call failure from Fact's function. Failures are from both LHS and RHS.

May I ask what is the best practice on handling these errors? Is there any mechanism allowing us to finish executing as much rules as possible and skip failed rules? 

(We are using Drools 8.*)

Any suggestion would be appreciated!
Thanks,
Leo

Kiran Bhanushali

unread,
Dec 11, 2024, 7:33:46 AM12/11/24
to Drools Usage
Hey,
Have you got any solution ?

Thanks,
Kiran

Toshiya Kobayashi

unread,
Dec 23, 2024, 2:45:50 AM12/23/24
to Drools Usage
You can use try-catch in RHS. You can also use a custom Exception handler : https://docs.drools.org/latest/drools-docs/drools/rule-engine/index.html#rule-base-configuration-con_rule-engine

For LHS, you can add null-check or use null-safe access `!.` (https://docs.drools.org/latest/drools-docs/drools/language-reference/index.html#ref-drl-operators_drl-rules).

However, there is no way to accept Exceptions in LHS. The best practice is

- Check facts before inserting to ksession

or

- Design fact classes not to allow invalid state e.g. null

Toshiya

2024年12月11日水曜日 21:33:46 UTC+9 Kiran Bhanushali:

Kiran Bhanushali

unread,
Dec 28, 2024, 1:51:27 PM12/28/24
to drools...@googlegroups.com
Thanks a lot!

--
You received this message because you are subscribed to a topic in the Google Groups "Drools Usage" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/drools-usage/HHibymAhcFU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to drools-usage...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/drools-usage/c3120057-6408-4aec-b687-1d6d01693e8an%40googlegroups.com.

L L

unread,
Mar 25, 2025, 4:53:53 PMMar 25
to Drools Usage
Thanks a lot! This is super helpful
Reply all
Reply to author
Forward
0 new messages