Fault Handlers
Errors (or faults) can occur when running a process. You can use Fault handlers to catch faults or exceptions and create fault-handling procedures to deal with potential runtime errors in your process definitions.
It is a best practice to use Fault handlers to catch faults or exceptions in a process. Two types of fault handlers are available: Catch Specific Fault and Catch All Faults.
Fault handlers can be defined at two different levels:
- Process level - When defined at the process level, allows you to catch fault in a process.
- Scope level - When defined at the scope level, allows you to catch fault within a scope.
Fault handlers when defined at the scope level, allows you to catch faults or exceptions generated by activities within a scope. To catch faults or exceptions specific to an individual activity, you need to define a new scope for that individual activity and attach a fault handler to the new scope.
At runtime, once a fault handler is run, the associated scope is not completed due to the error generated. If a fault is not generated in the fault handler, the process execution continues with the first activity that follows the scope. If a fault is generated in the fault handler, then the engine looks for an enclosing scope that is designed to handle the fault. If one is found, the engine runs it. Once the enclosing fault handler finishes its execution, the engine runs the next activity following the scope. If no fault handlers are found in the enclosing scopes, then the job ends with a fault.
Consider the fault handlers defined in the sample process.
Sample Fault Handlers
If an exception is caught in the inner scope, the exception is logged and the scope is completed. If an exception is caught in the outer scope, the exception is logged and the scope is completed. The process execution completes successfully as there are no following activities to be processed. An Exit activity inside the fault handler returns the control out of the scope and the process.
Error Transitions can also be used to handle error conditions by using them to specify a transition to take in case of an error.