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,
You will see a Dashboard as shown in below image and you can create a new bot through highlighted button 'create a bot'-
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
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.
After creating bot, we need to do below steps-
- Add Try catch block
- Expression to generate exception in Try block
- Add Throw
- Get Throw errors in Catch block
- 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.
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.
Let's create another variable of 'Number' type with name as 'OutputVariable'
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
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
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.
Let's create another variable of 'Number' type with name as 'ErrorLineNumber'
4.2 Catch Block: Select 'All Errors' in Exception and variables like 'ErrorMessage' in exception message & 'ErrorLineNumber' in line number.
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)
Where output will be look like after running the bot.
Conclusion
In this article, how to use exception handling in environment of Automation Anywhere.