0

I am trying to implement Exception Handling in ODM 8.5.1 as per the below URLs but couldn't find the setExceptionHandler method in the IlrContext class.

Please help me with the detailed process to implement it or provide any sample code which I can refer to understand it better.

http://www-01.ibm.com/support/docview.wss?uid=swg21400651

http://www-01.ibm.com/support/knowledgecenter/SSQP76_8.5.0/com.ibm.wodm.dserver.rules.designer.run/executing_engine_topics/tsk_rulesetexec_set_handler.html

1 Answers1

1

I'm not sure what you mean by "cannot find the setExceptionHandler" method, but I'm attaching some code snippets so maybe this will help clarify.

There are two different exception handlers that can be used dependent on the type of rule algorithm you are using.

If you are using RetePlus, you can use the setExceptionHandler that belongs to the IlrContext class (IlrContext javadoc )

The code for this look like:

package com.ibm.sample.exceptionHandler;

import ilog.rules.engine.IlrExceptionHandler; import ilog.rules.engine.IlrUserRuntimeException;

public class ruleHandler implements IlrExceptionHandler {

public ruleHandler(){   
}
@Override
public boolean handleException(IlrUserRuntimeException ex) {
    // TODO Auto-generated method stub
    if(ex.isInConditions()){
        System.out.println("Caught by rule handler");
        return false;
    }else{
        throw ex;
    }
}

}

And will catch any exception thrown in the condition portion of the Rule (again when using RetePlus).

You add this to the engine before execution - using the generated RuleEngineRunner class - simply by adding:

IlrContext engine = new IlrContext(ruleset);
**engine.setExceptionHandler(ruleHandler);**

The RuleflowExceptionHandler is similar for FastPath and Sequential, but gives you more options for determining where the exception took place (remember the ExceptionHandler for RetePlus is only in the rule itself).

public ruleFlowHandler(){
}
@Override
public boolean handleException(IlrUserRuntimeException ex) {
    // TODO Auto-generated method stub
    if(ex.isInConditions()){
        System.out.println("Condition error caught by ruleflow handler");
        return false;
    }else{
        if(ex.isInternal()){
            System.out.println("internal exception caught by ruleflow handler");
            return false;               
        }else{
            if(ex.isInActions()){
                System.out.println("Action exception caught by ruleflow handler");
                return false;               
            }else{
                System.out.println("Throw exception");
                return true;
            }
        }

    }
}

As you can see, we can now determine if the exception is in the Ruleflow itself, the Conditions portion of a rule or the Action portion of the rule. The handler is attached in the same way as the ExceptionHandler:

  IlrContext engine = new IlrContext(ruleset);
  **engine.setExceptionHandler(ruleFlowHandler);**

Both of those calls would be in your client java code. If you wanted to add these when running via something like HTDS, then just create a simple virtual BOM entry which adds the handlers to the current context.

In my example, the BOM/XOM mapping code for my static method looked like this:

context.setExceptionHandler(new ruleHandler());
context.setRuleFlowHandler(new ruleFlowHandler());

And I called the code from the Initial Action of the RuleFlow. In the case of RetePlus, I would have simply added a ruleset variable that would have constructed the exception handler when entering the ruleset.

In all cases, make sure that the exception handling code is in the classpath of your rule set/application.