Catch an Error with Try/Catch

You can catch errors in automation using the Try/Catch control.

Context

Refer to the following procedure to catch an error with the Try/Catch control.

Procedure

  1. Select the Create File in nested folder activity in the workflow. Click the button on the right side of filePath to open the Expression Editor.

  2. Delete the previously set expression and enter "C:\\RPADemo" + Step2.filename. Save your expression.

  3. Save and test your automation.

    An error has been raised. However, this error is caught by the On Error node and not by the Try control. The following message box appears:

    You can review the test data in the Test Console tab.

  4. Enter Log in the search bar on the Automation information side panel. Drag and drop the Log Message activity on the Catch branch.

  5. On the Log Message activity’s side panel, click the Expression Editor button on the right side of the message field.

  6. Enter "Error occurred:" + Step3.error.message and click Save Expression.

  7. Save and test your automation.

    The automation fails when it reaches the Create File in nested folder activity and goes to the On Error node (because we created a file path which raised an error).

    A message appears, stating that Something went bad. Click Ok. The testing session fails.

    You can review the test data in the Test Console tab.

  8. Click the Info tab at the bottom of your screen.

    The Log Message does not appear in the Info tab because the automation failed before reaching this part. The On Error node caught the error and stopped the main automation.

Results

You now know how to use the Try control in your automation. You also know which errors to choose and how to use them in an automation.