Automatic exception handling in conditions

The rule engine continues to process rule conditions that generate Java exceptions.

The following subclasses are handled by the rule engine:

  • ArithmeticException
  • NumberFormatException
  • NullPointerException
  • IndexOutOfBoundsException

With automatic exception handling in conditions, expressions in conditions that result in exceptions during their evaluation are treated as unknown values and are handled by the rule engine. The rule engine evaluates the overall rule condition by using the following three-valued logic:

The image contains the three-valued logic for the and, or, and not operators.

If the rule engine evaluates the rule condition as true or false, despite unknown values in the condition expressions, the rule action logic is applied. If the rule engine evaluates the rule condition as unknown, because of unknown values in the condition expressions, the rule is not fired.

For example, in the following rule, when the value of the name of the customer is null, and the age of the customer is 20, the first condition cannot be resolved, and the second condition is met:

if
   the name of the customer is 'Paul'
   or the age of the customer is 20
then
   reject the loan;

Because the rule uses the logical or operator, the action to reject the loan is taken. If the age of the customer is not 20, the first condition cannot be resolved, and the second condition is not met. In this case, the rule is not fired, and the loan is not rejected.

Supported business rule language expressions

Automatic exception handling currently supports the following two business rule language expressions:

  • If there is no ... then ...
  • If there is at least one ... then ...

The following business rule language expressions are not currently supported. However, if you decide to use one of the business rule language expressions not supported, understand that the rule engine currently ignores unknown values during the evaluation of the rule condition:

  • If there is no ... then ... else ...
  • If there is at least one ... then ... else
  • If there are at least <number> ...
  • If there are more than <number> ...
  • If there are less than <number> ...
  • If there are <number> then ... else ...

Apart from the expressions in the business rule language that are supported, all other expressions that use collections follow the same logic that ignores unknown values during the evaluation of the rule condition.

In the following example, if the where clause is true for two borrowers and unknown for two borrowers, then the rule engine considers that the rule condition is false. The else action is taken:

If there are more than 3 borrowers in the past borrowers of 'the loan' where the name of each borrower is the name of 'the borrower', 
then
   reject ‘the loan’;
   add “more than 3 similar borrowers found" to the messages of 'the loan' ;
else
   add “3 or fewer similar borrowers found " to the messages of 'the loan' ;

To enable automatic exception handling logs, set the Logger name com.ibm.rules.engine.aeh to FINE in your server.xml. For an introduction to the Java Logging API, see Java Logging Overview. For more information about the java.util.logging Java logger, see java.util.logging in the Oracle documentation.

Examples of automatic exception handling in conditions

Simple rule condition

In the following example, if the status of the borrower is unknown, no rule action is executed.

if
   the status of 'the borrower' starts with "duplicate"
then
   reject 'the loan' ;
   add "duplicate detected" to the messages of 'the loan' ;
else 
   add "no duplicate found" to the messages of 'the loan' ;
Rule condition that uses the OR operator

In the following example, if the status of the borrower is unknown and the comment of the loan contains the word duplicate, then the loan is rejected and a duplicate detected message is sent.

if 
   the status of 'the borrower' starts with "Duplicate" or the comment of 'the loan' contains "duplicate"
then
   reject 'the loan' ;
   add "duplicate detected" to the messages of 'the loan' ;
else 
   add "no duplicate found" to the messages of 'the loan' ;

However, if the status of the borrower is unknown and the comment is unknown, then no rule action is taken. The loan is not rejected and the message no duplicate found is not added to the loan.

Rule condition that uses the AND operator

In the following example, if the status of the borrower is unknown and the comment in the loan contains the word duplicate, neither the then nor the else actions are taken. In other words, the loan is not rejected and the message no duplicate found is not added to the message of the loan.

if 
   the status of 'the borrower' starts with "duplicate" and the comment of 'the loan' contains "duplicate"
then
   reject 'the loan' ;
   add "duplicate detected" to the messages of 'the loan' ;
else 
   add "no duplicate found" to the messages of 'the loan' ;

For the loan to be rejected, both expressions must be true.

Rule condition that uses the NOT operator

In the following example, if the status is unknown and the comment does not contain duplicate, the then action is taken and no duplicate found.

if it is not true that
   (the status of 'the borrower' starts with "duplicate" and the comment of 'the loan' contains "duplicate")
then
   add "no duplicate found" to the messages of 'the loan' ;
else 
   reject 'the loan' ;
   add "duplicate detected" to the messages of 'the loan' ;

If the status is unknown and the comment contains duplicate, no rule action is executed.

If there is no ... then ...

If the collection of past borrowers contains a borrower for whom the where clause is unknown, then no rule action is taken:

If there is no borrower in the past borrowers of 'the loan' where the name of this borrower is the name of 'the borrower', 
then 
add "no duplicate found" to the message of 'the loan'
If there is at least one ... then ...

If the collection of past borrowers contains a borrower for whom the where clause is true, then the rule action is taken. If the collection of past borrowers contains borrowers for whom the where clause is either false or unknown, then the rule action is not taken:

If there is at least one borrower in the past borrowers of 'the loan' where the name of this borrower is the name of 'the borrower', 
then 
   reject 'the loan' ;
   add "duplicate detected" to the message of 'the loan'
Rule variable

If the rule variable 'statusIsNew' is unknown, the rule engine stops the evaluation of the expressions. The condition is considered unknown and no rule action is taken:

definitions
   set 'statusIsNew' to the status of 'the borrower' starts with “New";

if it is not true that 'statusIsNew' and  the comment of 'the loan' contains "similar"
then
   reject 'the loan' ;
   add "duplicate detected" to the messages of 'the loan' ;
else 
   add "no duplicate found" to the messages of 'the loan' ;
Collection of objects

If there is an unknown value in the test that the collection object must fulfill, then this object is not added to the collection:

definitions
set 'duplicateBorrowers' to all borrowers where the status of each borrower starts with "duplicate" ; 
Expressions in the business rule language that are not supported

In the following example, if the where clause is true for three borrowers and unknown for one borrower, then the rule engine considers that the condition is true because the borrower for whom the where clause is unknown is not counted. The then action is taken:

If there are at most 3 borrowers in the past borrowers of 'the loan' where the name of each borrower is  the name of 'the borrower', 
then
   add “3 or less similar borrowers found" to the messages of 'the loan' ;
else
   reject ‘the loan’;
   add “more than 3 similar borrowers found" to the messages of 'the loan' ;

In the following example, if the where clause is true for one borrower and unknown for two borrowers, then the rule engine considers that the rule condition is false because the two borrowers for whom the where clause is unknown are not counted. The else action is taken:

if there are at least 3 borrowers in the past borrowers of 'the loan' where the name of each borrower is  the name of 'the borrower', 
then
   reject ‘the loan’;
   add “3 or more similar borrowers found" to the messages of 'the loan' ;
else
   add “less than 3 similar borrowers found" to the messages of 'the loan' ;