Exceptions Handling Mechanism

Each activity block has an “Error” port, or “red port,” as it is called. This is the port to which you can bind a set of activities to be performed if an error occurs during the main specified activity step.

Screenshot_91.png

Let’s take a simple example of error handling in the execution of an algorithm.

Suppose that our bot has to read text from some file. To do this, we use the Read text file activity but deliberately move the file itself before launching the bot so that the bot won’t be able to find it. For some time, the bot will try to find the required file but will eventually stop, and an error message will appear in the console:

Screenshot_92.png

Now let’s look at the exception-handling process itself. Let’s design the algorithm so that the bot displays the cause of the error in the notification window for the user.

  1. Specify a path to the file in the Read text file activity. The path should look like this:
    C:\Users{{Username}}\Desktop\Sample file.txt
  2. Move this file to some folder so that the path to the file changes, but we won’t change the “Path” parameter in the activity parameters.
  3. Add the Assign value to variable activity via the red port. You can set any name for the variable, for example, “exception.” In the “Variable value” parameter, pick the “Save the previous step result” option.Screenshot_93.png
  4. The next activity in the workflow will be the User notification activity. Pick the “Save the previous step result” option in the “Description message” parameter. You can specify any value as a “Button name” parameter.

Run the algorithm. The bot will try to find the file, but when it fails, a message will appear showing that there is no such file in the given path.! Screenshot_94.png|498x498

In reality, such a scenario can easily be foreseen and handled (by checking the file’s presence manually). In this example, we want to demonstrate an approach that could be used in such a scenario if the manual check cannot be performed before launching the bot so that you can see in a simple example the principle of exception handling.