3.8. Exceptions
Figure 3.3. A sample process using exception handlers
If an exceptional condition occurs during the execution of a rule flow, a fault will be raised. The rule flow will then search for an appropriate exception handler that is capable of handling this type of fault.
As with events, each fault has an associated type. They may also have associated data. You can define both your own types and your own data.
If the Fault node specifies a fault variable, the value of the given variable will be associated with the fault.
Whenever a fault is created, the process will search for the exception handler to match.
Rule flows and Composite nodes can both define exception handlers.
You can nest exception handlers; a node will always search for an appropriate exception handler in its parent container. If none is found, it will look in that one's parent container, and so on, until the process instance itself is reached. If no exception handler can be found, the process instance will abort, resulting in the cancellation of all nodes inside the process.
You can also use exception handlers to specify a fault variable. In this case, any data associated with the fault will be copied to this variable. This allows subsequent Action nodes in the rule flow to access the fault data and take appropriate action based on it.
Exception handlers need to be told how to respond to a given fault. In most cases, the behavior required of them cannot be expressed in a single action. Red Hat therefore recommends that you have the exception handler signal an event of a specific type (in this case "Fault") by using this code:
context.getProcessInstance().signalEvent("FaultType", context.getVariable("FaultVariable");
context.getProcessInstance().signalEvent("FaultType", context.getVariable("FaultVariable");