When an error occurs during the execution of a Java Action, an exception is thrown. Systemwalker Runbook Automation allows you to define your own error handling for erroneous Java Actions. In this way, you can prevent that a process instance goes into error state when an exception is thrown.
In addition, you can define actions for Java Actions which perform a "cleanup" before a transaction is rolled back and a process instance is set to the error state. This includes a rollback of all Java Actions in a Java Action Set, and allows you to perform general actions (e.g. sending notification emails in any error case), or executing some specific actions before setting the process instance to error state.
Systemwalker Runbook Automation provides the following options to handle errors in Java Actions:
Compensation Actions: Compensation Actions are used to clean up the system and to ensure a consistent state of all systems involved in a transaction, e.g. external databases or mail servers. Compensation Actions are particularly useful whenever external systems are involved.
If you do not define any error handling for a Java Action, the following happens: When an exception is thrown in this Java Action, the transaction will be rolled back. A rollback, however, is only possible for changes in the Application Server context. Any transactions in external systems cannot be rolled back, for example, if a row has been added to an external database. Therefore, it is sometimes necessary to manually clean up external systems to ensure a consistent state of all systems used in the transaction. Optionally, you can use Compensation Action Sets.
You can specify a Compensation Action for every Java Action in an Action Set. You can use a Compensation Action e.g. for removing a newly added row in a database or for sending out an additional email. If an exception occurs in a regular Java Action Set, all Compensation Actions defined for all Java Actions that have been successfully executed before the exception was thrown, are invoked in reverse order.
Note
You cannot embed a Compensation Action in another Compensation Action. If a Compensation Action throws an exception, the process instance will immediately go to error state, and the execution of remaining Compensation Actions will be aborted.
Error Actions: On Java Action level, Error Action sets will become active when an exception is thrown in the related regular Java Action. Error Actions are bound together in Action Sets, similar to all other Action Sets. Error Actions can be specified for any action inside an Action Set. Note that you cannot define an Error Action that handles exceptions occurring in an Error Action.
For every Error Action, you can specify additional error handling settings on an Error Handling tab. Note that this tab is only available when defining Error Actions for a Java Action. On process definition level and when defining Compensation Actions, defining error handling settings is not required.
Behavior after Error: Specifies the behavior of the process instance after executing the Error Action. You can specify that a process instance goes to error state or continues executing in case of an error.
Exceptions to React to: You can choose which kind of exceptions trigger the execution of the Error Action.
Note
In case an Error Action throws an exception, the transaction will be rolled back instantly and the process instance will go into error state. No Error Action can be defined for such a case.
To define Error and Compensation Actions for regular Java Actions:
Click the empty space in the Process Definition editor or select the node to display the Properties view for the process definition or the node respectively.
Select the Action Set tab.
The Properties view displays all Java Actions that are available for the selected process definition or node. If you have not yet defined any Error or Compensation Java Actions for a regular Java Action, empty folders for Error and Compensation Java Actions are shown. The following figure shows a Prologue Actions folder for an Activity Node, consisting of two Java Actions:
Figure 11.5 Properties view with Prologue Actions
Select the regular Java Action for which you want to define an Error and/or Compensation Action.
Select the Error Actions or Compensation Actions folder or any Error or Compensation Action inside the folder, and click Add.
The Action Type List dialog is opened where you can select a Java Action and add this action as a new Error or Compensation Action.
In the Action Type List dialog, expand the folder where the Java Action to be added is located. Select the Java Action, and click Create.
A dialog is displayed where you fill in the details for the selected Java Action. Perform operations required depending the action you selected.
When defining an Error Action for a Java Action: In the Action Editor for the selected Java Action, click the Error Handling tab. Here you can specify the following error handling settings:
Note
This tab is only available when defining Error Actions on process definition level or a regular Java Action. On process definition level and when defining Compensation Actions, this tab is not available.
Figure 11.6 Displaying the Error Handling Tab
Behavior after Error: Specifies the behavior of the process instance after executing the Error Action. Select the Goto Error State radio button if you want your process instance to go to error state. In case of an error, the Compensation Actions specified for the Java Actions and the Error Actions on process level are executed, the process instance is rolled back, and the instance is put to error state.
Select the Continue after Error radio button to continue executing your process instance. In case of an error, the exception gets caught, the Error Actions specified for the failed Java Action are executed, and the process instance continues. The default setting is Goto Error State.
Note
If you have defined several Error Actions with different settings, the Goto Error State setting overrides the Continue after Error setting.
Exceptions to React to: You can choose which kind of exceptions trigger the execution of the Error Action. If you want the Error Action to react on any kind of exception, select the Catch All Exceptions radio button. In that case, the Add and Remove buttons are disabled.
Select the Catch Specific Exceptions radio button if you want the Error Action to react on specific exceptions. In that case, you have to specify the exception class names (for example, java.lang.NullPointerException), using the Add and Remove buttons.
Note that if you specify java.lang.Exception as exception class, the behavior will be the same as when specifying Catch All Exceptions, because all exceptions belong to this class unless you are more specific.
You can combine all error handling settings. Each combination results in a different error handling procedure. The following table shows all possible combinations and their impact on executing the defined Java Actions:
Error Handling Settings | Goto Error State | Continue after Error |
---|---|---|
Catch All Exceptions | If a Java Action throws any kind of exception, the specified Error Action is executed. The transaction is rolled back, and the process instance goes to error state. | If a Java Action throws any kind of exception, the specified Error Action catches this exception, and the process instance continues. |
Catch Specific Exceptions | If a Java Action throws the specified exception, the Error Action is executed. The transaction is rolled back, and the process instance goes to error state. If a Java Action throws an exception that is not specified, the Error Action is not executed, the transaction is rolled back, and the process instance goes to error state (default error handling behavior). | If a Java Action throws the specified exception, the Error Action catches this exception, and the process instance continues. If a Java Action throws an exception that is not specified, the Error Action is not executed, the transaction is rolled back, and the process instance goes to error state (default error handling behavior). |
Fill in details for the selected Java Action, specify the Error Action behavior, and click OK.
The new Java Action is displayed in the Properties view. In the example, one Error Action and one Compensation Action have been added to the Prologue Action.
Figure 11.7 Adding Error and Compensation Actions