Setting an exception handler
You can set an exception handler to treat user code exceptions generated during rule execution.
About this task
At the rule level, you use the IlrContext.setExceptionHandler method to set the handler. Note that Rule Execution Server does not support exception handlers. Also, the exception handler is supported only by the RetePlus algorithm. The sequential and Fastpath algorithms support the handler only at the rule flow level and you set it by using the IlrContext.setRuleflowExceptionHandler method. You can set both at the same time to cover all cases.
Procedure
To set an exception handler:
IlrExceptionHandler exceptionHandler = new IlrExceptionHandler()
{
public boolean handleException(IlrUserRuntimeException ex)
{
if (ex.isInConditions())
return false;
else
throw ex;
}
};
engine.setExceptionHandler(exceptionHandler);
engine.setRuleflowExceptionHandler(exceptionHandler);
Results
During execution of a RetePlus engine or task, the execution continues if an exception handler is used. For the other algorithms and the rule flow, the execution is stopped and the rule flow exception handler, if any, is called.