Create an Error Flow¶
What is an Error Flow?¶
The drag&bot Studio is able to react to errors occurring in function blocks or programs. For example if a gripper does not close correctly, the function block of the gripper can throw an exception like CLOSE_FAILED. These exceptions can be handled inside the drag&bot Studio by executing different paths inside a program.
In the following diagram you can see how the architecture of drag&bot handles occurring errors.
Create a simple Error Flow¶
An exception inside a function block can be thrown like any other exception in Python1. To add a simple error inside your function block add the following line to the python code:
execute(): ... raise Exception("CLOSE_FAILED")
When the execution does reach the point where the CLOSE_FAILED exception is thrown the program will just stop and a toast in the drag&bot Studio will show a message like Unhandled Error: CLOSE_FAILED.
The video below shows how a function block with an error code can be created which needs to be handled in the drag&bot error flow.
Write your exception in capital letters and separate by underscore like ' MY_SIMPLE_EXCEPTION'.
Handle the Error Flow¶
When creating a program in drag&bot we can handle a potential error of a function block. We can react to these errors by adding actions to the paths.
- Open the builder.
- Add the function block to the program.
- Select on the added function block.
- Select to create a flow.
- Select the error handle CLOSE_FAILED.
- Add logic to the path.
More Error Handling Functionality¶
A function block can also react itself to a thrown exception. Therefore the
error() method can be used. This method is optional. The error method will be entered when the
execute() method does raises an exception. When using the error method we need to raise exception again in order to handle them in drag&bot.