What is Drools exception handling

Neka nam opisati drools iznimka rukovanje u detaljima. u drools, zadana iznimka rukovatelj je poznat kao “Posljedica Iznimka Handler”. Ona pruža minimum podataka kao što su sljedeće.

a) The rule
b) Where the exception took place
c) The cause with java stack trace

Drools also allow to write your own custom exception handler.The “ConsequenceException” proteže “java.lang.RuntimeException”.The constructor signature is given below.

ConsequenceException(Throwable rootCause, Rule rule)

The only method available is “public Rule getRule()”.

The “ConsequenceExceptionHandler” is an interface which is implemented to write custom handler.The only method available is given below and it is overwritten to do custom handling.

void handleException(Activation activation,
WorkingMemory workingMemory,
Exception exception)

Sample code is given below :-

import java.io.Externalizable;
import org.drools.runtime.rule.ConsequenceExceptionHandler;
public class CustomConsequenceExceptionHandler
implements ConsequenceExceptionHandler, Externalizable {
public void handleException( Activation activation,
WorkingMemory workingMemory,
Exception exception ){
// Write custom handling code here.
}
}

To improve custom handling “RuntimeException” can also be extended.

For identifying rule file (.DRL) compilation error, “hasErrors()” method of “KnowledgeBuilder” class can be used. Following is a sample code snippet for implementing the method.

KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newFileResource("D:/Workspace/TestProj/src/Test.drl"), ResourceType.DRL);

ako (kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors().toString());
throw new RuntimeException(“Nije moguće sastaviti ,,en,Test.drl ,,en”Test.drl\”.”);
}

============================================= ============================================== Buy best TechAlpine Books on Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Enjoy this blog? Please spread the word :)

Follow by Email
LinkedIn
LinkedIn
Share