How to handle Errors in UiPath
While creating a workflow it’s a best practice to handle the errors. We will learn how to handle those in UiPath.
There are two types of errors may occur
- Runtime Error
- Compile Error
To handle those errors we are having certain activities provided by UiPath as shown in the image below.
When we are creating a workflow we should use the above activities for error handling.
Basically it is a block having 3 sections and mostly used in every workflow.
By default, the activities mentioned in the Try Block would be executed and if there were any error it will be caught in the “Catch” Section. When we are creating small projects using a sequence or large scale projects using Flowchart we must use the “Try Catch” activity.
How does it work?
For example, we are automating a web portal. First, we will take the “Open Browser” activity. And by any chance, if it fails to load/get any error at Runtime your workflow may encounter an error. However, if we have proper error handling in the workflow the error gets caught in the “Catch” Section and executes that block as mentioned in the following image.
When there was an error that occurred in Try Block it will be caught in Catches block. Please note we can have multiple catches in Catch Block. After executing the Try-Catch Block robot will by default enter in “Finally” block.
Points to Remember
- The robot will execute “ Try” Block first
- If there is an error in the “Try” Block then only robot will execute the “Catches” Block.
- After executing the Try block robot will execute the “Finally” block in any condition.
Throw activity is such a type of mechanism wherein a case when bot fails to execute the mentioned activity throws an error with a specified error message to help us understand where was bot failed. When we trigger the process through orchestrator we may not be verifying the bot what actions he is performing hence “Throw” activity will help us in this regard.
We can handle two exceptions using this activity.
To handle system exception through specified error message we just need to drag and drop “Throw” activity from activity panel and write the exception message as per our need. For Ex. New Exception (“Exception in Main Workflow”)
While performing the actions from the workflow when robots encounter any error related to the third-party application such as website/database due to no data or error while loading the data such exception called as a business exception. We can handle that exception as well as using the “Throw” activity. For Ex. New BusinessRuleException (“Error occurred in web portal”)
Please note “Throw” activity will be helpful when we are having “For each” Loop going on hence if robot is encountered any error for the particular row it will skip the record and continue for the next iteration.
By using this activity robot throws an exception again which was caught previously while executing the workflow. For this activity, we didn’t need to provide any specified message. It will pick the last error message and attached it to the window accordingly.
This is a mechanism where we can ask the robot to terminate rest activities. This activity mostly used when there is no data to process or by matching certain conditions as per business rule. To use this activity we may need to provide the exception message which bot may log in the error log file which can be referred by the developer/business to get more details about run.
This is an important activity that we must use while designing the workflow. By using this we may trace easily where the robot was failed or it run successfully. For that, we just need to drag and drop “Log Message” Activity and we can log Error / Information / Warning / Trace / Fatal error if any.
Hope this will help you understand the error handling part. Please feel free to comment below if you have any questions.