...
  • December 3, 2021
  • Rohit Kashyap
  • 0

UIPATH-Exception Handling Techniques

What is an Exception?

In the world of computers, a programming exception is an event which occurs during the execution of a program that disrupts the normal flow of program’s instructions. Exception handling is the process of responding to the occurrence of exceptions. In other words, exception breaks the normal flow and behaves as per pre- defined error codes or when a special condition is met.

Managing a known and unknown exception plays a very important role in any programming language. It is a pillar of every programming language. Similarly, exception handling performs an extremely key role in UIPATH as well.

UIPATH is a platform where most of the time a robot executes at virtual machines, specifically in the case of the un-attended robot where a user doesn’t have visibility of the processing part. In such scenarios, it becomes very important to deal with the exceptions in the robot very smartly. Otherwise, an unknown exception will abort the process and the user will not be able to get any alert until the user logs in to the orchestrator and checks manually.

With the exception mechanism you can write your code much “cleaner” and have everything “automatically handled” and user friendly.

Few pointers going to cover in UIPATH

1.         How many types of exceptions are there in UIPATH?

2.         What all activities are there in UIPATH to deal with known and unknown scenarios.

3.         Most common error users face in RPA UIPATH.

Different Types of Exceptions in UIPATH: –

There are two types of exceptions we generally found in UiPath..

  1. Business Exception
  2. System Exception

What is Business Exception?

A Business exception describes an error rooted in certain data which the automation project depends on, is incomplete or missing. Such a situation is, for example, a project which read column data from excel sheet provided by the business and that column is missing in the provided file.

We also call business exception as a user defined exception when we apply business rule to our project and if the condition is not satisfied in such situation, we must declare business exception into the code. Retrying the transaction does not yield any chance of solving the issue, and there are other better courses of action, such as notifying the human user of this error.

Another good example of business exception scenario is when you are login into the application and the credentials is changed from the backend in such case bot will try to login and throw a business exception stated Invalid username password.

How to throw Exceptional Business Exception in UIPATH Tool?

Business Rule exception

Wherever you are checking a business rules and conditions are not fulfilling you can use a Throw Activity in the else part and raise a business exception.

Syntax of creating business exception.

Creating business exception

How to capturea Business Exception in UIPATH Tool?

a. Go to the Catch part of try catch.

b. Drop down the Exception Area.

Exception area

c. Browse the Business exception class.

Business exception class

d. Select the exception. After doing these steps under business section area you can mention your action which you want to take it on business exception scenario.

What is System Exception?

System exception can occur due to the unavailability of the item which you declared in your process, and it can occur at any point of time. For example: – A project where a URL need to open in browser and that URL is not responding, in such cases you will encounteran exception which will cover under system exception.

System Exception and Application Exception are similar.Only difference is Application Exception describes an error rooted in a technical issue, such as an application that is not responding. Whereas System Exception is thrown by the common language runtime when errors occur that are nonfatal and recoverable by user programs. You can perform a multiple retry on this exception and if after that it is not recovered you can notify operation team.

How to catch a System Exception?

Below are the steps by using that you can capture the system exception.

Catch a system exception
  • In the Catch section you select the System. Exception Class.
Exception class
  • After selecting the System Exception option, you will this screen in Drop Activity area you can drop you further actions.

Most Common System Exception which you will face in UiPath are below: –

  1. Null reference Exception
  2. Unable to communicate with the browser
  3. Unable to find the element with the selector
  4. System.IO.FileNotFoundException
  5. UiPath.Core.SelectorNotFoundException
  6. System.NullReferenceException
  7. System.ArgumentException 
  8. System.ArgumentNullException

In UIPATH there are different types of Activities available such as: –

  1. Rethrow
  2. Terminate Workflow
  3. Throw
  4. Try Catch

Rethrow – Throws a previously thrown exception from within a Try Catch activity. The error is rethrown retaining the original source of the exception. Rethrow can only be used within a Catch block of a Try Catch activity. In more simple language it is rethrowing the same error to outer try catch block. This most commonly when you are working in framework and with multiple workflow module.

How to Use Rethrow Activity?

Rethrow activity
  • a. Search Rethrow activity from activity panel.
Activity panel
  • Drag and drop rethrow activity into catch part.

Terminate Workflow: –To terminate a Workflow Job at a specific time and throw a specific exception, you can use the Terminate Workflow activity. The Terminate Workflow activity immediately ends the Workflow Job with the specified exception and a Final Severity of “Error”.

Terminate workflow

a. Searches terminate activity in the activity panel.

Terminate activity

b. Drag and drop Terminate Activity.

Exception box

c. Declare the exception in the exception box.

Declare the exception reason

Throw: – To generate a user defined exception we can use Throw Activity. By using Throw activity, you can apply all the business scenario validation in your code. For example: – suppose in project you are receiving excel file with 10 columns. So, you can put a validation if the file is not “.xls” type or number of columns is less than or greater than 10 and create a business exception and send a mail to all the required stack holder so they can correct the format of the file and provide it again.

Search Throw activity

a. Search throw activity into the activity panel.

Property of the throw activity

b. Declare your exception in the property of the Throw activity.

Try Cath Workflow: – Try catch is the main back bone of the code. Wherever it feels like there is possibility of error Try Catch is the activity which can help you to capture your error and handle it nicely so that your process will not interrupt, and other transaction will complete.

Catches a specified exception type in a sequence or activity, and either displays an error notification or dismisses it and continues the execution.

The activity has three main sections:

Try – holds the activity that could throw an exception.

Catches – specifies the exception type and, optionally, holds an activity that informs the user about the found exception.

Finally – holds an activity that should be executed only if no error occurred or if the error was already caught.

There is no limit to how many Catches you can use in a Try Catch activity.
Keep in mind that this activity requires at least two of the three fields to be in use. You cannot run it only with the Try field completed.

Recent try catch
  • Search try catch activity in activity panel and drop in the main workflow.

Or You can right click on sequence or activity which you want to put under try catch condition.

try catch conditions
click on sequence or activity
  • Select you exception type in catch part from the drop-down list and declare your exception actionable.

Leave a Reply

Your email address will not be published. Required fields are marked *