RPA flow to use the Throw and Rethrow activities
Create a basic flow to use the Throw and Rethrow activities. This flow also demonstrates handling exceptions using the Try Catch, Throw, and Rethrow activities.
Pre-requisites for flow creation
To create this RPA flow, you must ensure:
- An RPA folder is created.
- A .txt file is created within the RPA folder. For example,C:\RPA\Exception_example.txt
Creating a flow
This section lists the steps required to create an RPA flow using the Throw and Rethrow activities.
- Log on to the RPA Studio application. The home page is displayed. Note: The application may prompt you to sign on to a tenant, if not already done.
- Click . The New Project screen is displayed.
- Specify this information in the Properties panel:
- Name
- ThrowRethrow
- ProjectLocation
- Retain the default value
- Description
- Throw and Rethrow
- Language
- VB. This is selected by default.
- Add a Sequence to the canvas containing the Try Catch block. The Try Catch block contains the Try, Catches and the Finally blocks.
- Add a Sequence in the Try block that contains the Read Text File, Message Box and an If Else activity.
- Configure the sequences as follows:
- Read Text File - This activity references the text file that we created in the
pre-requisites section.
- Specify the path of the file in the Source Filepath field of the Input property. For this example, we can create a file path argument of type string with a default value "C:\RPA\Exception_example.txt".
- The Text field in the Output property displays the text that was read. For this example, we can create an op variable of type string without a default value.
- Message box: This activity displays the text that was read.
Specify the op variable in the Text field of the Input property. The op variable contains the text.
Exceptions are handled in the Try Catch block. Hence Throw or Rethrow activities usually go hand in hand.
The Try block includes the activities or sequences that produce an exception. Here the activity Read Text File and a Message Box to display the contents are added. At this stage, an exception is produced when the Read Text File does not find a file in the referenced path.
- Throw - Simulates an exception. This enables you to manually produce an exception that you want. The Throw activity can be used anywhere in your flow where an exception is appropriate.
- Rethrow - Rethrow works in conjunction with the Catch block of a Try Catch activity and throws an exception that is caught in the Catch block.
- Read Text File - This activity references the text file that we created in the
pre-requisites section.
- Add an
If the value of exceptionCondition is set to true, we must add the Throw activity inside the Then block to trigger and throw an exception
block to simulate an exception.
For the Condition field, create the exceptionCondition variable of type Boolean. - Specify new System.IO.IOException(“Input Output Exception“) in the Exception property of the Throw activity.
- Specify the Message Box for Else. The input Text property contains: “False - else
statement” to indicate that the control is in else.
For this example, set the exceptionCondition as true so that we always trigger the Then block and Throw an exception.
If no exception is thrown, the workflow does not go to the Catch block, but in case the File is not found, then the Catch block is triggered. For our Catch Block select System.IO.IOException and start adding the activities.
First add the Sequence as otherwise you would be able to add a single activity within this block. For troubleshooting, add Message Box to show the expectation and specify the text as <>
The Catches block contain the Rethrow activity, which will just Throw back the Exception that was caught and terminate the workflow. This exception can be seen in the Error window.
The Finally block is simple indicators of where the control is in the sequence. The Finally box contains a Message Box with Input text “In Finally block”, to indicate to the user that the control is in Finally block.
The last three activities, Message Box, Throw and Message Box are optional activities to to check where the control was during the execution of the flow. Both the Message Box displays texts like “This Message Box is outside Try Catch, before Throw” and “This Message Box is outside Try Catch, after Throw”, while Throw contains new Exception("This exception is outside of try catch block") in the Exception property.