How to create an RPA flow using Try-Catch activity

Business Problem

Handle exceptions with the Try-Catch activity. This activity can be used with any of the RPA Activities that might throw an exception in a scenario, and is also equipped with handling exceptions thrown by specific RPA Activities, such as OCR, Workflow, Web, etc.

To help us understand the basics of one of the many use cases this activity will help us with, we will take an example of working with Excel. Now, in a lot of scenarios, we will be using our Excel Activities. When you run an RPA flow that uses the Excel activities, if the Excel application is open, the activities won’t be executed, and you will get a 500 error. We will handle this scenario using Try Catch.


  • RPA Management
  • RPA Studio
  • Excel Desktop application


  • Before we start building the flow, you’ll need to have an Excel workbook available locally.
  • Also, you’ll need to install RPA Studio on your machine and set up a connection between the RPA Studio and RPA Management, the on-premise component and multitenant component, by using the connection files from API Gateway. Check the Infor RPA Studio User Guide for the steps on how to do so.


1 – Open RPA Studio on your machine. If you are not signed in already into the Tenant, you would be asked to sign in before proceeding to RPA flow designer screens.

2 – On the Home page of RPA Studio click Create New Project and specify the following properties in the pop’up window:

(a) Name: TryCatchExcel

(b) ProjectLocation: <default>

(c) Description: Try Catch with Read Range in Excel.

(d) Language: VB <selected by default>.

3 – TRY – In our case, any Excel activity will not run if Excel is running. These activities could be anywhere in the RPA Flow but to make things simple, I have just started with drag and dropping Try Catch activity, next I will look up a “Read Range” activity and placed it in the Try block. Now, when this RPA Flow runs, and if Excel is running, this activity will encounter an error. Now for this activity to throw an exception at this point, be sure to uncheck the Continue on Error property in the Properties panel. Any activity will only throw an exception when the Continue on Error is unchecked. Be sure to output the DataTable in a variable. We will use this variable to validate whether the Excel was read or not later. If Excel is running, an exception will be thrown which we will catch in the Catch block.

4 – CATCH – There can be different types of exceptions and they are caught using appropriate Exception classes. In this case we will simply use System.Exception to catch ours.

Along with catching the exception, we can add an activity or a sequence here to handle that exception. Here, we have added a sequence that contains a message box. The message will display the Exception we have encountered and also the further instructions to handle it. “exception.message” will display the exception encountered.

The below input can be given to the “Input Text” property of the Message box:
exception.message + “RPA cannot access Excel since it is open. Pls close Excel and click on OK to proceed.”

We ask the user to close Excel before proceeding and then click on OK on the message box. We have used a Delay to allow the user to complete these actions.

5 – Finally – Finally block executes irrespective of whether an exception was caught or not. We will take advantage of this property to validate whether our Excel was running in the background or not. We will place an IF block inside the Finally and check “dt is Nothing”. This is a check for whether the variable where “Read Range” was giving an output is empty or not. In case, Excel was running, “Read Range” will not work, and nothing will be stored in dt. If there is an output in dt, this means Excel was closed and the activity worked.

If Excel was open at first and then had to be closed, then it means we would need to read it again using “Read Range”.

If Excel was not running, then nothing needs to be done.

6 – Click on “Run” to run you RPA Flow.