An unwanted unexpected event that disturbs the normal flow of the program is called Exception.
For example, consider that you want to go shopping on Sunday. But when you are prepared and traveled to the mall but the shop you are looking for is shut for the day. Here you might not have expected the shop is shut, but currently, it is shut. Your expectation did not work out, and this is an exception in day to day life.
Similarly, in UiPath there is a situation where you might see this kind of exceptions, for example, you want to read the file contents but the file you are trying to read might not be present at the given location.
If you thinking like I have verified the file then only I have created the flow, then think about executing the same program in different computer, in such situation will you able to say that file is present ?. no, it is not possible and due to this reason, we have to make a flow where we perform some task when the file is not present and this alternate flow is known as exception handling.
Performing an alternate flow or performing a set of a task when an exception arises known as Exception handling.
Whenever an exception occurs most programming languages and tools will crash the execution of the current task. This might cause severe problems when you are dealing with sensitive data like financial transactions.
So we have to avoid the crash either by providing alternate ways of execution or stop the program gracefully with clearing the sensitive data.
Exception Handling mainly deals with handling errors with respect to various activities in UiPath. The Error Handling activity offers four options:
Following example demonstrate the Exception handling
Create a new process called Exception_Handling_Example
Once the Exception_Handling_Example process opened in the UiPath Studio, add Open Browser activity inside the sequence and then enter the google URL(www.google.com) as shown below.
Next, add Type Into activity inside the DO Container of the sequence and then click on Indicate element inside browser and indicate the google search box on the browser(Make sure that the browser has opened). Next, enter the text you want to search on the Google search box.
Click on the three horizontal lines on the Type into activity and select Edit Selector.
Edit the name in the Edit Selector Wizard( I am changing
name='z') and then click on the ok button. The
name='q' has automatically generated from the selector if we change the name from
z then we will get an exception.
By creating an error scenario, we will understand how the exception happens and then how to handle this exception. Save and run the sequence, You will get an
These are very realistic scenarios in our production, we have to handle this kind of run-time exceptions happened in our production. These exceptions can be handled with the help of Try Catch Block.
Add Try Catch activity inside the sequence and move the Type Into activity inside the Try block. And then select the exception type which you are facing. If the exception type which you are facing is not present in the list then click on the Browser for Types... and search for it.
I am clicking on Browser for Types... and search for
So, the error message will be displayed on the output screen when you run the sequence.
So, whenever an error occurs in the Try block it will jump to the catch block and instead of stopping the execution It will display a
The Finally block is the place where you want to execute something even if the error occurs or even if the error does not occur. Now, add Close tab activity inside the Finally block meaning that if the error occurs or not occurs the tab will be closed.
When you do not name the activities :
When some other application is open in front of the main application: It may happen sometimes that you are working on the N number of applications on your system. But, when you execute the project you forget to make sure that the main application in which the automation has to be done is open, and no other window/application is open in front of that.
When you have timing and synchronization issues: It may happen sometimes that you are dependent on some other application to perform some task, and that application may take time to load. In such situations, if you do not mention the time to wait, then UiPath assumes that the application is not working/opening and throws an exception.
When your browser crashes : Sometimes, when you work with the browser, it may happen that browser crashes. In such situations, UiPath will not understand the dependency and will throw an Exception that it cannot load/open.
When you do not choose the right activity : Sometimes it may happen that you may choose the wrong activity. For example, if you search for For each activity, then you will see that there are three for each activity that can be chosen.