In the development of UiPath Studio, we can make the robot run stably by implementing the processing when an error occurs.
However, many people with no programming experience are confused because they have no experience in error handling.
This article explains how to handle errors with try-catch and retry scopes and throws.
\Save during the sale period!/
Take a look at the UiPath course on the online learning service Udemy
*Free video available
Related Articles Learn the Creation Techniques f UiPath robotics creation with Udemy’s online courses that take it up a notch
This site was created by translating a blog created in Japanese into English using the DeepL translation.
Please forgive me if some of the English text is a little strange
- Type of error
- Processing according to the content of the exception occurrence (Try Catch).
- Raises an exception at an arbitrary time (throw)
- Exception handling according to the type of exception
- List of major exceptions
- One of the arguments passed is invalid (ArgumentException)
- Exception on null object reference (NullReferenceException)
- Exception when an I/O error occurs (IO.IOException)
- Invalid method call exception (InvalidOperationException)
- When using an index out of bounds (IndexOutOfRangeException)
- Specified selector does not exist (SelectorNotFoundException)
- Invalid cast or conversion exception (InvalidCastException)
- Business exception handling (BusinessRuleException)
- Logging when exceptions occur
- Process again when an exception occurs (retry scope)
- Error handling (Rethrow) in higher-level workflows
- Terminate Workflow when an exception occurs
- Continue processing when an exception occurs
- Summary
Type of error
The types of errors are divided into application exceptions and business exceptions.
application exception
An application exception is an error caused by a technical problem, such as a system or network problem.
Some examples of application exceptions in UiPath are
- Selector not found and cannot be clicked
- The specified file cannot be found.
- Converted a string variable to numeric type.
- A variable of data table type specified a matrix that does not exist.
Business Exceptions
A business exception refers to the fact that the data used in an automated process is incomplete from a business perspective.
Business exceptions in UiPath include, for example
- Data where the product price exceeds the limit
- Data with incorrect product codes
- Product data that has been purchased by a department that does not have the authority to make the decision
Processing according to the content of the exception occurrence (Try Catch).
The “Try Catch” activity is used to continue processing depending on the nature of the exception raised.
“Try Catch” is located in System> Activities> Statements.
- (1) Try block
Places processing that may cause an exception. - (2) Catches block
Performs processing according to the type of exception. It is also possible to place multiple types of exceptions. - (3) Finally block
Places the final processing to be done regardless of whether or not an exception occurs.
Try Catch Setting item
Setting Location | Setting item | Setting Contents | |
Properties | Common | DisplayName | The display name of the activity. |
Misc
|
Private | If selected, the values of variables and arguments are no longer logged at Verbose level. |
It raises an exception by converting characters to integers, outputs error messages to the log with Catches, and outputs the exit message to the log with Finally.
・Try block
・Catches block
・Finally block
・Execution result
Raises an exception at an arbitrary time (throw)
If you want to raise an exception at an arbitrary time, use the Throw activity.
The Throw can be found in System> Activities> Statements.
Throw Setting item
Setting location | Setting item | Setting contents | |
Properties | Common | DisplayName | The display name of the activity. |
Misc
|
Exception | Exceptions thrown by the activity. | |
Private | If selected, the values of variables and arguments are no longer logged at Verbose level. |
Throw raises an error, Catches outputs an error message to the log, and Finally outputs an exit message to the log.
・Try block
– Throw properties
・Catches block
・Finally block
・Execution result
Exception handling according to the type of exception
List of major exceptions
例外の種類 | 例外の説明 |
System.Exception | All exceptions |
System.ArgumentException | One of the arguments passed is invalid. |
System.NullReferenceException | Exception on null object reference |
System.IO.IOException | Exception when an I/O error occurs |
System.InvalidOperationException | Invalid method call exception |
System.IndexOutOfRangeException | When using an out-of-bounds index |
SelectorNotFoundException | Specified selector does not exist. |
BusinessRuleException | Business Exceptions |
One of the arguments passed is invalid (ArgumentException)
ArgumentException exception will be thrown if any of the arguments passed are invalid.
Sample Process
- Reads a CSV file as a data table
- Specify a non-existent data table by its column name in the Try block
- Picks up ArgumentException exceptions in the Catches block and outputs error messages to the log
- Output messages to the log with Finally block

・Read CSV Properties
・Cathes block
・Finally block
・data.csv contents
・Execution result
Exception on null object reference (NullReferenceException)
NullReferenceException exception is thrown when a null object is referenced.
Sample Process
- Reads a CSV file as a data table
- Specify the number of rows in the data table that do not exist in the Try block
- Picks up NullReferenceException exceptions in the Catches block and logs error messages
- Output messages to the log with Finally block

・Read CSV Properties
・Catches block
・Finally block
・data.csv contents
・Execution result
Exception when an I/O error occurs (IO.IOException)
IOException exception will be raised when an I/O error occurs.
Sample Process
- Delete a text file with Try block
- Catches block to pick up IOException exceptions and log error messages
- Output messages to the log with Finally block

・Catches block
・Finally block
・[Data] folder
・Execution result
Invalid method call exception (InvalidOperationException)
Invalid method calls will result in a System.InvalidOperationException exception.
Sample Process
- New variable of type List
- Output the first value of list1 of List variable to the log in Try block
- Pick up the InvalidOperationException exception in the Catches block and output the error message to the log
- Output a message to the log with the Finally block

・Catches block
・Finally block
・Variables
・Execution result
When using an index out of bounds (IndexOutOfRangeException)
If an out-of-bounds index is specified, System.IndexOutOfRangeException will be thrown.
Sample Process
- Assign {10,20,30} to a variable of type Array
- Specify a non-existent index number for the Array variable in the Try block
- Picks up the IndexOutOfRangeException exception in the Catches block and outputs the error message to the log
- Output a message to the log with the Finally block

・Catches block
・Finally block
・Variables
・Execution result
Specified selector does not exist (SelectorNotFoundException)
If the specified selector does not exist, SelectorNotFoundException will be thrown.
Sample Process
- Click on the search window on the Yahoo top page with the Try block
- Pick up SelectorNotFoundException exception in the Catches block and output the error message to the log
- Output message to the log with Finally block

・Catches block
・Finally block
・Click Properties
・Execution result
*Run the process without opening the IE browser
Invalid cast or conversion exception (InvalidCastException)
Invalid cast or explicit conversion will result in a System.InvalidCastException.
Sample Process
- Try block to convert character a to Int type
- Catches block to pick up InvalidCastException exception and output error message to the log
- Output messages to the log with Finally block

・Catches block
・Finally block
・Execution result
Business exception handling (BusinessRuleException)
If you want to raise an error in your business, throw a BusinessRuleException.
Sample Process
- Try block to throw BusinessRuleException
- Catches block to pick up BusinessRuleException exceptions and output error messages to the log
- Output messages to the log with Finally block

・Catches block
・Finally block
・Throw Properties
・Execution result
Logging when exceptions occur
Take Screenshot
If you want to identify the screen where the error occurred, you can use Take Screenshot and Save Image to save the error screen
Take Screenshot is located at UI Automation>Element>Attribute.
Save Image is located at UI Automation>Image>File.
Take Screenshot Setting item
Setting location | Setting item | Setting contents | |
Properties | Common | DisplayName | The display name of the activity. |
ContinueOnError | Specifies if the automation should continue even when the activity throws an error. This field only supports Boolean values (True, False). | ||
Output | Screenshot | The resulted screenshot. The field supports only Image variables. | |
Options | WaitBefore | Delay time (in milliseconds) before taking the screenshot of the specified UI element. The default amount of time is 300 milliseconds. | |
Misc
|
Private | If selected, the values of variables and arguments are no longer logged at Verbose level. | |
Target.Selector | Text property used to find a particular UI element when the activity is executed. It is actually a XML fragment | ||
Target.TimeoutMS | Specifies the amount of time (in milliseconds) to wait for the activity to run before the SelectorNotFoundException error is thrown. | ||
Target.WaitForReady | Before performing the actions, wait for the target to become ready. | ||
Target.Element | Use the UiElement variable returned by another activity. | ||
Target.ClippingRegion | Defines the clipping rectangle, in pixels, relative to the UiElement, in the following directions: left, top, right, bottom. |
Save Image Setting item
設定場所 | 設定項目 | 設定内容 | |
Properties | Common | DisplayName | The display name of the activity. |
ContinueOnError | Specifies if the automation should continue even when the activity throws an error. | ||
Input | FileName | The full file path where you want to save the image, and its name. | |
Image | The image that you want to save to your disk. | ||
Misc | Private | If selected, the values of variables and arguments are no longer logged at Verbose level. |
Sample Process
- Click on the Yahoo! top search window in the Try block of Trycatch (open the msn.com screen when the process is running, and raise SelectorNotFoundException).
- In the Cathes block, output the error message to the log and save the screenshot as a file with the date and time.
- In the Finally block, output the message to the log.

・active window
・Click Properties
・Catches block
・Finally block
・Take Screenshot Properties
・Assign Properties
・Variables
・Execution result
・Screenshot image file output destination
Log Message
Use Log Message to output the error level and message to the log.
The Log Message can be found in Programming > Debug.
Log Message Setting item
Setting location | Setting item | Setting Contens | |
Properties | Log | Message | The message you want to log. |
Level | The severity level of the message to be logged. | ||
Common | DisplayName | The display name of the activity. | |
Misc | Private | If selected, the values of variables and arguments are no longer logged at Verbose level. |
Logging Levels in UiPath
Log Level | Default Logs | User-Defined Logs |
Off | None | None |
Critical | All messages logged with Critical level or higher. | All messages logged with Critical level or higher. |
Error | All messages logged with Error level or higher. | All messages logged with Error level or higher. |
Warning | All messages logged with Warning or higher. | All messages logged with Warning or higher. |
Information | All messages logged with Information or higher. | All messages logged with Information or higher. |
Trace | All messages logged with Trace level or higher. | All messages logged with Trace level or higher. |
Verbose | All messages logged with Trace level and Workflow Tracking logs. | All messages logged with Trace level. |
Output log messages for each level.
・Execution result
Process again when an exception occurs (retry scope)
If an exception occurs during the process and you want to do the same process again, you can use the “Retry Scope” activity.
The Retry Scope is located in Workflow > Control.
- (1) action blocks
Place the activity to be retried. - (2) condition blocks.
Place an activity that returns a Boolean value to determine if it should be retried
(EX: Element Exists , Image Exists , Text Exists)
retry scope Setting item
Setting location | Setting item | Setting Contents | |
Properteis | Options | NumberOfRetries | The number of times that the sequence is to be retried. |
RetryInterval | Specifies the amount of time (in seconds) between each retry. | ||
Common | DisplayName | The display name of the activity. | |
ContinueOnError | Specifies if the automation should continue even when the activity throws an error. | ||
Misc | Private | If selected, the values of variables and arguments are no longer logged at Verbose level. |
Repeat the process for the search window on the Yahoo top page until the click and element detection succeeds or fails five times.
・Retry Scope Properties
・Click Properties
・Element Exists Properties
・Variables
・target site(Yahoo!のtop page)
・Execution result
*Display the Yahoo! top page after 9 seconds of process execution.
Error handling (Rethrow) in higher-level workflows
When an exception occurs, use “Rethrow” to perform error handling in the upper-level workflow.
Rethrow is located in System> Activies> Statements.
Rethrow Setting item
Setting location | Setting item | Setting location | |
Properties | Common | DisplayName | The display name of the activity. |
Misc | Private | If selected, the values of variables and arguments are no longer logged at Verbose level. |
Sample Process
- Calling a workflow file in the Try block of a higher-level workflow
- Throw BusinessRuleException in the Try block of the lower workflow
- Re-throwing in the Catches block of the lower-level workflow
- Output an error message in the Catches block of the upper workflow
- Output a message in the Finally block of the upper workflow

・Catches block in the upper workflow
・The Finally block of the upper workflow
・Subordinate Workflow
・Catches block for lower-level workflows
・Finally block in the lower level workflow
・Throw property of lower-level workflow
・Execution result
Terminate Workflow when an exception occurs
To terminate the workflow when an exception occurs, use “Terminate Workflow”.
The “Terminate Workflow” is located in System> Activites> Statements.
Terminate Workflow Setting item
Setting location | Setting item | Setting contents | |
Properties | Common | DisplayName | The display name of the activity. |
Misc | Private | If selected, the values of variables and arguments are no longer logged at Verbose level. | |
Exception | Gets or sets the exception that caused the termination of the instance. | ||
Reason | String input argument containing the reason for terminating the workflow instance. |
Sample Process
- In the Try block, convert a character to an int type and raise an exception.
- In the Catches block, terminate the workflow after outputting an error message.

・Catches block
・Finally block
・Terminate Workflow Properties
・Execution result popup
・Execution result
Continue processing when an exception occurs
If you want to continue processing when an exception occurs in an activity, set the “ContinueOnError” checkbox in the properties of the specific activity to True.
Examples of activities that have the “ContinueOnError” property are “Click”, “Get Text”, and “Extract Structured Data”.
Summary
- Exceptions are divided into application exceptions, which are caused by technical issues such as systems and networks, and business exceptions, which are caused by incomplete data from a business perspective.
- Try-catch is divided into Try block, which arranges the processing that may cause errors, Catches block, which handles errors according to the type of exception, and Finally block, which arranges the final processing to be done.
- If you want to raise an exception at an arbitrary time, use throw.
- If you want to process again when an exception occurs, use the retry scope.
\Save during the sale period!/
Take a look at the UiPath course on the online learning service Udemy
*Free video available
Related Articles Learn the Creation Techniques f UiPath robotics creation with Udemy’s online courses that take it up a notch
same category UiPath

Japanese IT engineer with a wide range of experience in system development, cloud building, and service planning. In this blog, I will share my know-how on UiPath and certification. profile detail / twitter:@fpen17