Error management with BOS
How do you deal with connector errors during the execution of your BOS processes?
This article will present two different ways to deal with errors in your processes: error events and exceptions. We will provide an example for each, and we will give you their pros and cons so you can choose the one that best fits your needs.
Sending and Receiving error events
This method allows you to associate a error with a name to a connector. If the connector fails, the process will catch that error with a boundary error event associated to that error name.
This will provide an alternate path that is taken to deal with your error.
However, this method has some major drawbacks:
- One can only associate a single named error to a connector, even if it can throw different types of errors. For example, for a database query connector, the server might be down or your query’s syntax might be incorrect, but the error raised by the failed connector will be the same.
- Upon receiving the error signal, you will no longer have access to the name of the error that occurred.
Throwing and Catching Exceptions
Another solution which is more complex, but also more powerful, is to use Java exceptions for error handling.
In this case, if you are developing your own connectors and using the Bonita API to execute some tasks, you can catch the exceptions that are raised by your connector.
Here is an example of a process that executes a task via a subprocess:
In this example the parent process will execute a "Caller step."
This caller step will launch the subprocess and execute the “Exception throwing step” with this method:
This automated task will execute a connector that throws a Java Exception. This exception will be then be thrown by the execute task method and can be used to provide appropriate error handling.
You can log the error and even store the Exception object as a reference to the last error that occurred.
Errors happen - so it's useful to deal with them in advance with boundary events or exception handling.
You may download the example processes from the contribution page here: Error management sample processes for BOS 5.5.1