Good day all, I have a sequence and I want to put try catch. What would be the right way to do it so that whatever exception can be caught:
You can add multiple Catch blocks, each configured to intercept a particular exception type (e.g., System.Exception for general errors, or more specific exceptions like SelectorNotFoundException). Within each Catch block, you define the actions to be taken when that specific exception is caught, such as logging the error, sending notifications, or attempting corrective actions.
Hi,
System.Exception will catch any exception.
If it’s necessary to handle exception depending on the type of it, you can add other exception type OR use “IF” activity etc. inside catch block to blanch process by type, message etc.
Regards,
Under the catch block simply choose system.exception and good to go. if you want you can put log message .
Happy automation
Step-by-Step Guide
- Drag the Try Catch activity into your workflow from the Activities panel.
- Place activities/actions in the Try block** that may cause errors (e.g., interacting with a UI element, reading from a file).
- Add one or more Catch blocks—each can catch a different type of exception (e.g., System.Exception, BusinessRuleException). In each, specify what to do if that exception is caught (e.g., log the error, display a message).
- Optionally, add activities to the Finally block for actions that should run regardless of errors (commonly for releasing resources or logging completion).
- Check below video
Mark solution if its help
https://youtu.be/XFZzIU9oBuE?si=Rmg3q-Zr_23c5AI7
Hi @Anelisa_Bolosha1 ,
Exception Handling is inevitable in creating/designing a stabilized production ready code that is capable of managing a situation involving Exception.
Coming to your question, How to configure Try-Catch
There is really no one way to do that, best way to configure your catch block is based on what youbare doing in your try block. For example inside your try block, lets say you are interacting with a browser doing some operations , in this scenario we can expect a browser related exceptions such as UiPath plugin not available with that browser, Browser not responding etc..,
The exception class in catch howeever encapsulates all types of exceptions.
We can go with approach to catch the exception using actions tailored to the expected exceptions like browser, excel , database, file etc..,
Or more common Exception handling like
Business rule Exception
Log the bre
Update in queue/db
Rethrow
Exception
Log the Exception
Update in queue/db
Rethrow
Hope this provides a bit more clarity.
Sincere request when you have a topic posted in community if you come across a reply that really helps you,please mark that as solution so that when someone searches for same question they would be able to find the thread and get an answer quickly.
Happy automating!
@Anelisa_Bolosha1 You are in the right Path.
You need to perform few steps to Catch the exception. To handle any type of exception, select “System.Exception” in the catch section.
Use WriteLine or Log message “exception.Message.ToString” to get it in your console.
To get the actual exception type you can use
“exception.GetBaseException.GetType.ToString” at you log message.
Please mark it as Solution, if it helps in your Query.
The Try Catch activity in UiPath is your essential safety net for building robust automations. You place any activity that might fail inside the Try block. If an error, or “exception,” occurs, the workflow doesn’t crash; instead, it automatically moves to the Catch block. Here, you can specify different actions for different types of errors—like a SelectorNotFoundException for UI issues or a FileNotFoundException if a file is missing. It’s smart to have a general System.Exception catch block to handle any unexpected errors. Finally, the Finally block is guaranteed to execute, no matter what happens, making it the perfect place for cleanup tasks like closing an application or deleting temporary files. This structure ensures your automation can handle errors gracefully and continue running, preventing unexpected failures.
Hi @Yoichi , I am processing emails from outlook, so for example I would want for when the bot catches an exception on maybe 1 of the emails, I send an email (already done this one) then I don’t want it to stop because there was an exception on that one email I want it to continue to process others, how do I do that?
Hi,
Basically, nothing to do in exception block if System.Exception is caught by Try-Catch, as the following image.
However, it may be better to log which email fails to send in order to do recovery.
Regards,
Okay so instead of using System.Exception I should use a specific one if I know which exception might be caught, because you saying when I use System.Exception it will not continue to process others?
Hi,
There are some ways to handle it.
For example, let7s say you add System.Exception and System.ArgumentException to catch block.
If ArgumentException occurs in try block, System.ArgumentException block will be processed.(System.Exception block will NOT be processed.)
If some exception except ArgumentException occurs, System.Exception block will be processed.(System.ArgumentException block will NOT be processed.)
Or we can handle exception type in each block, as the following, for example.
Regards,
Alright thank you, I will open another topic for this one
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.