📣 Welcome to Day 7 of the UiPath Studio Web Workshop. In this session, we will delve into the critical topic of exception handling in UiPath Studio Web. Join us as we explore robust strategies such as Try-Catch, Finally, Retry, and Throw to ensure your automation is resilient and gracefully recovers from unexpected errors.
👉 Topics covered:
The Role of Finally
Retry Mechanisms
Throwing Exceptions
Demonstrating Try-Catch, Finally, Retry, and Throw in action
Speakers:
Vajrang Billlakurthi, Digital Transformation Leader, Vajrang IT Services Pvt Ltd. and UiPath MVP
Swathi Nelakurthi, Associate Automation Developer, Vajrang IT Services Pvt Ltd
Rahul Goyal, SR. Director, ERP Systems, Ellucian and UiPath MVP
👉 Visit the series page to register to all events.
3. 3
• Overview:
- "Try Catch Finally" is used to handle exceptions and errors that may occur during the execution of a workflow. These
activities are essential for building robust and fault- tolerant automation processes.
- Try Catch Finally:
• Try: This is where you put the activities that you want to execute. These activities are the ones that might throw
exceptions during runtime. The Try block encapsulates these activities.
• Catch: This is where you handle any exceptions that occur within the Try block. You specify the type of exception
you want to catch (e.g., System.Exception) and what actions you want to take when that specific type of exception
occurs. You can have multiple Catch blocks to handle different types of exceptions.
• Finally: This block is optional. It contains activities that you want to execute regardless of whether an exception
occurs or not. This block is typically used for cleanup actions, such as closing files or connections.
• Retry:
- The "Retry" activity is used when you want to retry a specific set of activities a certain number of times or until a
specific condition is met. It is often used in scenarios where network issues, temporary glitches, or intermittent
errors may cause a workflow to fail
• Activity Body: Container where you can specify the activities
• Condition: You can set a condition that, if met, will stop the retry attempts even if the maximum number of retries
has not been reached. This is useful when you want to stop retrying after a certain condition is satisfied
Exception Handling
4. 4
• Throw and Rethrow
• Throw:
- In UiPath, the "Throw" activity is used to manually generate an exception during the execution of a
workflow. This can be useful for various purposes, such as error handling or to force a specific behavior in
your automation process.
- When you use the "Throw" activity, you specify the type of exception you want to throw and provide an
optional message to describe the exception. This activity is typically used within a Try-Catch block or at
specific points in your workflow where you want to handle exceptions.
• Throw activity:
- Example Expression: New Exception(“An error occurred while reading the file.")
• Rethrow activity
- In UiPath, the "Rethrow" activity is used within a Catch block of a Try Catch activity. It throws a previously
caught exception. This allows the exception to be propagated to higher levels of exception handling.
- When an exception occurs within a Try Catch block and is caught by a Catch block, "Rethrow" allows you to
pass the exception to the next higher level of exception handling. This is useful if you want activities to occur
before the exception is thrown. It enables you to handle the exception at different levels of exception
handling or perform additional logging or cleanup operations before the exception is ultimately dealt with.
5. 5
• Scenario:
- Retrieve a list of text files from Orchestrator Storage bucket, read the text and display their content.
• Requirements:
- Create a storage bucket named “StorageTextFiles” in the Orchestrator storage bucket to store text files.
- Upload Text files to the StorageTextFiles bucket. The following are the text files to be uploaded: 1.txt, 2.txt, 3.txt,
4.txt, 5.txt, 6.txt.
• Projects Objective:
- The project aims to retrieve text files from the "StorageTextFiles" bucket, read their content, and display the results.
- The scenario addresses handling exceptions, ensuring the process continues smoothly even if any file is missing
from the bucket
• Variables Used:
- StorageFilesList (IEnumerable<StorageFileInfo>) : This variable holds the list of storage file information
- currentItem: This is the autogenerated variable that holds each file's information from the list.
- ReadStorageTextResult: This variable holds the text file’s extracted text data using Read Storage Text activity.
Example Process on Exception Handling
6. 6
• Get Storage Files List
- Use the List Storage Files activity to list the content of a certain directory in an Orchestrator storage bucket
• Orchestrator Folder Path: Provide the folder path in which your storage bucket exists (e.g., Shared).
• Storage Bucket name: Provide the storage bucket name (e.g., StorageTextFiles).
• Directory: Provide “” for the directory.
• The Result is the autogenerated variable of type IEnumerable<StorageFileInfo>, which holds the list of storage file
information. Create a new variable named StorageFilesList of type IEnumerable<StorageFileInfo> in place of the
autogenerated variable for better understanding.
• Log Files Count
- Use the Log Message activity to o log the count of files retrieved from the storage bucket.
• Message: The message format is specified as StorageFilesList.Count to display the count of files
Workflow Overview
7. 7
• Iterate through each file:
- Use For Each activity to iterate through each file
• Provide the StorageFilesList variable in List of Items
• "currentItem" is the autogenerated variable that holds each file's information from the list.
- Inside the For Each:
• Read the Text Files:
• Use the Read Storage Text activity to read each text file from the list of files
- Orchestrator Folder Path: Provide the folder path in which your storage bucket exists (e.g., Shared).
- Storage Bucket name: Provide the storage bucket name (e.g., StorageTextFiles).
- File Path: Provide currentItem.FileFullPath, i.e., we are getting the text file (e.g., 1.txt).
- The Result is the autogenerated variable that holds the text file’s extracted text data using Read Storage
Text activity. Create a new variable named ReadStorageTextResult of type string in place of the
autogenerated variable for better understanding.
• Display the result:
• Use Log message activity to display the result
- Message: "Text File "+currentItem.FileFullPath+" data is"+Environment.NewLine+ReadStorageTextResult.
8. 8
• Raise a scenario to show an exception:
- Add a breakpoint at the Read Storage Text activity.
- Test the process. The process pauses the automation at the breakpoint.
- Process Till breakpoint:
• Run the process, which pauses at the breakpoint.
• The automation successfully retrieves the list of files and logs the count as 6.
• It iterates through each file, holding the data in the currentItem variable
• Delete Text Files From StorageTextFiles bucket:
- Manually delete any 2 text files (e.g., 2.txt and 5.txt) from the StorageTextFiles bucket.
• Return to Process:
- Resume the process after deleting the files.
- The process attempts to read each file from the storage bucket.
- Due to missing files, it encounters an exception ("BlobFileInfo does not exist. Error code: 1002").
- As a result, the automation stops abruptly without processing the remaining files.
• Exception Handling Analysis:
- The scenario highlights the importance of robust exception handling.
- Without proper handling, encountering an exception disrupts the automation flow and prevents processing of
subsequent files.
9. 9
• How to Handle Exception:
- Let's restore the deleted text files, specifically 2.txt and 5.txt, back into the StorageTextFiles bucket. This action is
essential to ensure that we have a sufficient number of text files to effectively demonstrate our exception
handling mechanisms.
• Try Catch activity
- Use Try Catch activity to handle exceptions
- To address the exception encountered during the reading of the storage text,
• We should relocate the "Read Storage Text" activity into the Try block.
• Additionally, transfer the Log Message activity responsible for outputting the extracted storage text result into
the same Try block.
• Handling Exceptions
- Now, the workflow will attempt to read the text if it's available and output the result. If the file doesn't exist, the
execution will transition to the Catch block where activities within it will be executed.
• In the Catch block, add an Exception variable to catch any exceptions.
• Insert a Log Message activity within the Catch block to output the exception message caught by the Catch
block.
• Test the process at a breakpoint to pause the execution.
• Manually delete "2.txt" and "5.txt" from the "StorageTextFiles" bucket.
• Return to the UiPath process and resume testing.
10. 10
• The process will attempt to read each file and extract the text from it.
• For "1.txt", since the file is available, the Read Storage Text activity will read the file and store the extracted
text in a variable.
• Use a Log Message activity to display the result.
• However, for "2.txt", as the text file has been deleted, the process will check for its existence.
• Since the file is not found in the "StorageTextFiles" bucket, it will throw an exception stating "BlobFileInfo does
not exist. Error code: 1002".
• In this scenario, even if we encounter an exception, the process will not abruptly stop. It will provide details of
the exception and continue processing the next file.
• For instance, after successfully reading and outputting the results for "3.txt" and "4.txt", when attempting to
process "5.txt" (which was deleted), the process will check for its existence. Since the file is missing, it will
throw an exception stating "BlobFileInfo does not exist. Error code: 1002". However, the automation will
continue smoothly, proceeding to read "6.txt" and outputting its results.
• This demonstrates how exceptions can be handled gracefully, allowing the automation to continue processing
subsequent tasks without interruption.
11. 11
• Conclusion:
- In this task, we have successfully demonstrated the importance of exception handling in UiPath automation
processes. By retrieving text files from the Orchestrator storage bucket, reading their content, and displaying the
results, we encountered a scenario where missing files caused exceptions.
- Through careful implementation of Try Catch activities, we were able to gracefully handle these exceptions
without disrupting the automation flow. By relocating the "Read Storage Text" activity into the Try block and
adding a Catch block to handle exceptions, we ensured that the process continued smoothly even when
encountering errors.
- Furthermore, by testing the process at breakpoints and manually deleting files to simulate real-world scenarios,
we verified that our exception handling mechanisms functioned effectively. Despite encountering exceptions,
the automation continued processing subsequent tasks, demonstrating the resilience and reliability of our
solution.
- In conclusion, proper exception handling is essential for building robust and fault-tolerant automation processes
in UiPath. By implementing Try Catch activities and handling exceptions gracefully, we can ensure the stability
and reliability of our automation solutions even in the face of unexpected errors or issues.