Throw and Rethrow

Suppose I have an invoked workflow enclosed by try catch , inside the workflow I have thrown several system exception. What would be the significance/usage of catch block if I catch the exception and use “Throw” instead of “Rethrow”.

You don’t want to put Throw nor Rethrow into the Catch block. The point to the Catch block is to handle the error that was thrown within the try, not to throw another error from the Catch. The purpose of doing this is to avoid the Job faulting. If you put a Throw or Rethrow in the Catch then the Job will fault, which is what you’re trying to avoid in the first place by using a Try/Catch.

Try
// processing steps
Catch
// steps to perform if there is an error

@Ritaman_Baral

Throw - This is used to throw a new exception …we have to provide the exception message that we want to throw

ReThrow - this is generally used in catch block if we need to propagate the same error futher but there are few steps to perform before poping the error out

We can use throw again but the original error would be suppressed and a new error will be thrown if Throw is used in Catch instead of Rethrow

Hope this helps

cheers

2 Likes

rethrow can only be put into the catch block. sometimes you may need to do some actions in the catch block before propagating the error further

e.g.

Try
// processing steps
Catch
// perform certain actions e.g. update log / click on error popup etc…
// rethrow to REFramework to handle exception (send email / take screenshot / update queue item ) etc…

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.