Catch action in Error handler
- Updated: 2023/07/05
Catch action in Error handler
Use the Catch action in the Error handler package to take control of the bot execution when an error occurs within the Try action.
You can assign values for the error description and the line number to variables within the Catch action. You can add additional actions within a Catch block to handle errors. These actions can include an Email Send action (sending an email about the error), a Log to file action (logging the error condition to a file), or a Screen Capture window to capture a screenshot of the window or application when the error occurs.
You can use the Try and Catch actions multiple times in a bot. This enables you to run a different set of actions based on any exceptions that might be encountered.
Consider a scenario where you want to copy a file from one location to another, open this file to view it, and then log any errors that are encountered during this process. You can use the Copy and Open actions from the File package in the Try block. You can then use the Log text to file action in the Catch block to capture any errors encountered during the bot run. The following image shows the flow for this sample scenario:
Settings
- Use the Exception drop-down to select Error
handler.
The Error handler applies to all the exceptions or errors that are encountered in the Catch block. You can then use the Assign exception message to field to provide a variable to store the exception message.
- Select the On error, continue with next action check box.When you select the On error, continue with next action check box, even if there is an error from an action in the Catch block, no exception is thrown and the bot continues to the next action.Note: This enhancement applies to all the nested actions in the Catch block. For example, you add a nested Catch block inside an existing (main) Catch block. If you select the On error, continue with next action check box in the main Catch block, errors from any of the actions in the nested Catch block are also handled (ignored).
- (Optional) Use the Assign exception message to field to
select an existing variable.
Use this field to provide a variable to store the exception if any of the actions encounter an error. For example, if you have used the action and it encountered an error, the Assign exception message to can be used to review the error message. The error message must be stored in a variable that you reference when logging the error so that you can have some insight into what has caused the issue. If there are no existing variables, click the Create variable icon to create one.
- (Optional) Use the Assign the line number to field to select
an existing variable.
Use this field to provide a number variable to hold the exact line number where an error occurred in the Try action. Like the exception error message, the line number is also stored in a log file for troubleshooting and further investigation. You can use the line number in either the List or Dual view of the bot editor to review the actions.