How To Use Rethrow In UiPath

Exception handling is one of the most important aspects of any programming, and it is something that will help us control any unseen issues during the executions.

UiPath also provides us the same feature to implement robust bots, by using Try Catch activity.

It has got two exception activities namely “Throw” and “ReThrow”.

In this article, we will try to learn about ReThrow activity…

Why ReThrow Activity?

Rethrow” activity in UiPath takes an existing exception that has been encountered and regenerates it.

ReThrow Activity Example

Implementation using UiPath :

For the purpose of this example, we will implement a robot, which will ask the user for the input.

And we will display him the data back by removing any spaces in it at the beginning or the end.

Note: If he doesn’t provide any data, we will log it down first and then try to throw an exception.

This activity always comes in the catch block of Try Catch activity

Step 1:
Drag “Input Dialogue” activity into the design panel and store the user provided value into a variable.

UiPath Rethrow Example 1.PNG

Step 2:
Drag “Message Box” activity into the design panel and use the code “user_Input.Trim” in it to display the cleaned data (.i.e data without any spaces in it) to the user.

UiPath Rethrow Example 2.PNG

Step 3:
Now by dragging “Try Catch” activity into the design panel, try to drop the above-implemented sequence into this try catch.

Note: “Try Catch” activity demands  at least one catch to be implemented

UiPath Rethrow Example 3

Step 4:
We are here going to handle two types of exceptions,
One is generic exceptions and another being a null reference exception.

First, let us implement, a generic exception and whenever it occurs we will suppress it and will log it using “Log Message” Activity”.

UiPath Rethrow Example 4.PNG

Step 5:
Second, we will implement, a null reference exception and whenever it occurs we will try to throw it.
UiPath Rethrow Example 5.PNG

So finally, we have implemented a process where we are handling different exceptions in a different way

When the generic error pops up, we are logging it


When a null reference error pops up, we are throwing it…

UiPath Rethrow Example 6.PNG

Click here to download the Source Code…

Hope it has helped you…

Leave a Reply