◷ Reading Time: 3 minutes
Error Handling Behaviour
Business Rules errors can be handled in three different ways using type ErrorHandlingBehaviour:
- Throw: Throws the exception and stops the execution
- Resume: Ignores the exception and continues the execution
- Collect: Continues the execution whilst collecting the exceptions in a Notification group called Exceptions
Throw
This is the default behaviour. IT means if an error happens during execution of a business rule at Runtime, the execution stops and engine will throw an exception to application. Application then can handle the error accordingly.
Resume
In this mode, once an error happens, the engine continue execution and ignores the exception. Engine will not throw any exception back to the application. Therefore some results might be unexpected as errors are ignored and execution continuous.
Collect
The behaviour at runtime is similar to the Resume mode, the difference is the exception is collected in the Notification and can be collected later once the execution is completed.
Handling Errors
This is a Runtime behaviour which means your application code should prepare the engine for execution. The preparation should apply on the engine instance only once prior to the execution.
.Net Environment
When an engine instance is create using RuntimeEngine then method SetRuleErrorHandler can be used to set up the behaviour.
Create RuntimeEngine Instance
var model = // read model content;
var engine = RuntimeEngine.FromXml(model);
Setup the Handling behaviour
The behaviour can be set to either of Collect, Resume or Throw.
engine.SetRuleErrorHandler(ErrorHandlingBehaviour.Collect);
Collect Exceptions
Once, the engine’s error handler is set, calling CollectRuleErrors on the RuntimeResult will return list of exceptions.
var res = engine.Run(); // Run engine with required parameters.
IEnumerable<Exception> exceptions = res.CollectRuleErrors();
JavaScript Environment
JavaScript Business Rule Engine does not support this at the current version.
FlexRule Server Environment
FlexRule Server execution does not support this behaviour at the current version.