How to use Throw and ReThrow

Hi all,

Can we Execute UiPath Process by using application program interface?
Thanks.

1 Like

Only if you have your Robots connected to Orchestrator.
https://orchestrator.uipath.com/v2018.1/reference
https://platform.uipath.com/swagger/ui/index#/

2 Likes

Thank you, Ovi.

1 Like

Please find below attachment,
Main.xaml (10.5 KB)

Cheers,
Pankaj

3 Likes

@ClaytonM please post a workflow to explain your post.

2 Likes

Hi @danesh,

Check out the post right above here:

The Exception you use in the Throw depends on what you are looking to throw. In his example, he is using a FileNotFound exception, but you can use others. And, if needed, you can also place a Rethrow in the Catch and it will throw the exception that had occurred. (to be honest, I use Rethrows temporarily more for troubleshooting than actually a part of my code; it’s a good way to pause and figure out what errors are happening, although you can also use a Message Box with the below information and is just as good)
exception.Source+"__"+exception.Message

6 Likes

The functionality of Throw is clarified. Could anyone please elaborate a scenario differentiating where Rethrow can be used and how it differs from Throw. The statement “activities are occurred before exception” is a bit confusing. what is it exactly meant by. Can anyone share the knowledge explaining through examples how throw and rethrow are differentiated??

4 Likes

Hi,
I´m not the most technical person and I might say something wrong, so please correct whoever knows, but from what I´ve seen…

Let´s say you´ve got a try/catch activity where the try throws an exception. If you put a Rethrow activity in the Catch block and run the robot from UiPath Studio, then you will get the pop-up window with the exception message and details, and the robot will stop.

On the other hand, if you run that same process from Orchestrator, I think that the robot will give you the error details, but it will continue running.

Please, correct me if I am wrong.

2 Likes

Hi @ander.labaka

Welcome back!

No, the idea of throwing an exception is to either stop the process or handle that particular exception. If you re-throw an exception, it will stop the process no matter if it was run from Studio during development or from Orchestrator.

8 Likes

I have implemented an example for the same and what i have observed is…

  1. If i put throw in my Try block it will just throw whatever customized exception I have included in my throw. This will just through a pop up displaying the exception message.
  2. If the same has been handled used Rethrow in Catch block, an exception is thrown instead of a message box and the process is stopped abruptly. This exception is like any other exception containing the information mentioned in Throw(Source, Message, Exception)
3 Likes

This is correct. If you have an exception and you catch it, it will not stop your process. However, When you rethrow in the Catch block, then it will need to be caught in a Try-Catch above or else it will throw an exception an stop the process.

8 Likes

Thanks.

new Exception(“Throwing an exception because something went wrong”)

4 Likes

Hello Guys!

I tried using the throw and rethrow but I’m always getting the throw message in the catch even if there’s no error in the code. Would you be able to help on how to use rethrow and throw properly? I’m using throw and rethrow because I want to customize the error message that I’m having. Thanks

Cheers

3 Likes

What I did was

Try catch

throw (new exception (“msg”)
Steps
Catch
System.exception (exception.message"

3 Likes

@bdavidov - In simple terms Rethrow is used when you want activities to occur before the exception is thrown. Throw activity is used when you want to throw error before the execution of the step

3 Likes

Hello @sandipauti

How are you? Would you be able to help me to share your knowledge on how to use throw and rethrow or use customize exception? if you have a simple sample, please share. thanks

3 Likes

@Callos_James_AU - I am good thanks , To create your own custom exception like new Exception(“Some message”) just use throw exception activity and pass exception message like Throw(new Exception(“Some message”))

5 Likes

Hey guys,

Hope this might help you :slight_smile:

Regards,
Sharath Raju

1 Like

Can throw be used inside a catch ? The GetAppCredentials of old RE framework has throw inside catch but it is not getting trigerred. What is the solution for it?

Hi All,

Here is the workflow which will show the correct use of Throw activity within try catch
Practise Solutions for Forum.zip (97.2 KB)
Main.xaml (26.0 KB)

Before running the workflow just do the following 2steps :-

  1. Within try catch Inside type into activity Enter Wrong username & Password of naukri.com website if you have
  2. Within Catch Inside type into activity Enter your correct username & Password of naukri.com website if you have

Hope this workflow may help you to solve the query
Mark as solution if this helps you and like it :innocent:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

2 Likes