How to choose the type of exception in try catch

Hi everyone,

I am beginner in uipath. I am studying about try catch activity in uipath.
And I dont know what is the best practice to choose the type of exception in catches part and how to use each type of exception. I searched on internet but I haven’t found any good documents, examples about this. If you have any good documents about this, please let me know.
Sorry, because my english is not so good.

Thanks and Best Regards,
Hoang Anh.

3 Likes

Hi,
Try Catch Activity in UiPath is similar to the Error Handling concept in programming languages.

The group of activities which you may expect failure can be placed inside the Try block and resolution activities for the error is placed inside the catch block.

You can catch the error based on exception type and can create handling for that exception individually or else you can use generic exception which catch whatever exception occurs.

Final- Activities inside final block will be executed irrespective of the error occurrence. Final is not mandatory but catch is.

Look into this XAML file try_catch.xaml (7.5 KB)

7 Likes

thanks you so much, ranjith.
It helps me a lot.

Small correction - neither of them is individually, but you have to have at least one of them. Try-Catch, Try-Finally and Try-Catch-Finally are all valid combinations.

5 Likes

How does it work with two catches? In my workflow, I have a try catch within a for each, so for each row of the data, if i tell it to throw it will go to the catch, and do the next line of data.

I have just experienced the application im using, whilst entering the row information, crash. Is there a way to “catch” this crash, which comes through as an “activity timeout” message, but with this error, end the for each completely and end the workflow??

It would mean that even though it throws within the for each to this particular catch, i would need the for each to end completely as well…or is there another way to catch IF the application you are using has randomly crashed (activity timeout), THEN end workflow?

thanks!

sophie

Hi @SophieSquash,

Choose a specific exception type in catch part, so you can have the suitable processing according to that kind of exception.

Best Regards,
Hoang Anh.

Thanks Hoang

I’m more stuck on how it would throw in the try catch within the for each activity, but instead of going back to the for each to do the next row of data, end the workflow instead. Or would simply putting that (end of workflow sequence) in the catch of the activity timeout error do it?

sophie

Hi @SophieSquash,

  • If you want to end the workflow:
    • Terminate workflow.
  • If you just want to exit the for each loop:
    • Use “Break” activity.
    • Put “for each” activity inside the try catch.

Best Regards,
Hoang Anh.

1 Like

i want to handle exceptions ( user defined exceptions) while open browser
any one help me please