Exception Handling In Automation Anywhere

Introduction

This article describes how to handling any exception in Automation Anywhere using the community edition. Sometimes we get exceptions in our bot and we have to deal with those exceptions & track them. So I will explain the same in this article.

If you are a beginner then need to check this article Getting Started Robotic Process Automation using Automation Anywhere to create environment of Automation Anywhere.

Create a New bot

After logging to Automation anywhere account through cloud community edition link,

Exception Handling in Automation Anywhere

You will see a Dashboard as shown in below image and you can create a new bot through highlighted button 'create a bot'-

Exception Handling in Automation Anywhere

Bot Configuration

After clicking on 'create a bot' button, you will get a popup window. It will ask some information about bot which you want to create like-

  • Name of bot
  • Description of bot(optional)
  • Folder location of bot

Exception Handling in Automation Anywhere

After clicking on choose option, a popup window will come where you can browse 'CSharpCorner' folder and click on choose to set a default location for your new bot.

Exception Handling in Automation Anywhere

After creating bot, we need to do below steps-

  1. Add Try catch block
  2. Expression to generate exception in Try block
  3. Add Throw
  4. Get Throw errors in Catch block
  5. Show message in Catch block

Add Try catch block

Let's go to 'Action' pane on left side and find 'Error handler' action. Drag & drop 'Try, Catch and Finally' into the workspace.

Exception Handling in Automation Anywhere

Expression to generate exception in Try block

In the 2nd step, we will generate exception through expression and for this we have to create 2 number variables, one for expression and second for the outcome of the expression

2.1 Create Number Variables: Create a variable through left side variable pane and click on '+' sign, and select 'Number' type and name as 'NumberVariable' and click on create button.

Exception Handling in Automation Anywhere

Let's create another variable of 'Number' type with name as 'OutputVariable'

Exception Handling in Automation Anywhere

2.2 Assign Values: Go to 'Action' pane on left side and find 'Number' section. Drag & drop 'Assign' into workspace. Follow the below steps

  • Fill source number as 0.
  • Select 'NumberVariable' to assign value

Exception Handling in Automation Anywhere

Now add another 'Assign' for expression and outcome into workspace with following steps-

  • Add expression in source-100/$NumberVariable$
  • Select 'OutputVariable' as destination variable

Note: We will get an arithmetic exception (Division by Zero) because we are dividing 100/0 as Number variable value is 0.

Add Throw

Go to 'Action' pane on left side and find 'Error handler' action. Drag & drop 'Throw' into workspace. Fill below details in throw-

  • Enter error message
  • Select 'AllErrors' as Error handler in Exception

Exception Handling in Automation Anywhere

Catch Block

Get all the 'throw' errors in 'Catch' block, which we got through 'Try' block, but we need to create 2 variables to store Error message and Error Line Number.

4.1 Create Variables: Create a variable through left side variable pane and click on '+' sign, and select 'String' type and name as 'ErrorMessage' and click on create button.

Exception Handling in Automation Anywhere

Let's create another variable of 'Number' type with name as 'ErrorLineNumber'

Exception Handling in Automation Anywhere

4.2 Catch Block: Select 'All Errors' in Exception and variables like 'ErrorMessage' in exception message & 'ErrorLineNumber' in line number.

Exception Handling in Automation Anywhere

Show Errors

At last, we need to show Error message and Error line number through 'MessageBox' action. Fill the below details like-

  • Window Title
  • Message to display( where we will add 'ErrorMessage' & 'ErrorLineNumber' variables)

Exception Handling in Automation Anywhere

Where output will be look like after running the bot.

Exception Handling in Automation Anywhere

Conclusion

In this article, how to use exception handling in environment of Automation Anywhere.


Similar Articles