As the above link in the comment(by Prog_G) says I implemented the ConsequenceExceptionHandler and handled the exception gracefully in the handleException method, I logged the failed fact and removed it from executing the further rules, sample code is given below. Hope this help someone having similar use cases.
//Drools Session creation
KieBaseConfiguration kconfig = new RuleBaseConfiguration();
kconfig.setProperty(ConsequenceExceptionHandlerOption.PROPERTY_NAME, "com.xxx.RuleExceptionHandler"); // set my exception handler name to RuleBaseConfiguration
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieBase kieBase = kContainer.newKieBase("ims-hw-rules",kconfig); // create KieBase passing the config
KieSession kSession = kieBase.newKieSession();
//ConsequenceExceptionHandler Implementation.
public class RuleExceptionHandler implements ConsequenceExceptionHandler{
@Override
public void handleException(Match match, RuleRuntime workingMemory, Exception exception) {
//if(exception instanceof MyException) {
if(match.getObjects().size() >0) {
for (Object object : match.getObjects()) {
JSONData fact = (JSONData) object;
//logFailedFact(fact);
}
}
if(match.getFactHandles()!= null) {
for (FactHandle factHandle : match.getFactHandles()) {
workingMemory.delete(factHandle); // delete the failed fact from executing remaining rules.
}
}
//}
}
}