How to intentionally throw an error from a workflow script

Jon Parrish
Tera Expert

Hello,

What is the proper way to intentionally throw an error from within a workflow run script activity?  I don't mean catching any random error with a try/catch block.  I need to intentionally throw an error such as (throw "something broke"';).  I have added the error condition to my activity, and I see that it is triggered when activity.state == 'faulted', but when I set activity.state to faulted using an if/else statement, the error condition/path is not used once the activity exits.  I am trying to cancel the remainder of the workflow if a particular scenario occurs, but every attempt to throw an error or set the activity.state to faulted just continues down the 'good' path.  Thank you for any help you can provide.

1 ACCEPTED SOLUTION

DrewW
Mega Sage
Mega Sage

Use a try/catch to trap any error and then just set the result to error or failed or some such and add a custom branch to the workflow activity that looks for that and then connect that to the workflow end or what ever activity is next in your error branch.

View solution in original post

3 REPLIES 3

DrewW
Mega Sage
Mega Sage

Use a try/catch to trap any error and then just set the result to error or failed or some such and add a custom branch to the workflow activity that looks for that and then connect that to the workflow end or what ever activity is next in your error branch.

MrMuhammad
Giga Sage

You can use throw to throw a custom error. in the run script you can use below

throw "500"; //replace 500 with your custom error. 

 

Please mark this correct & helpful if it answered your question.

Thanks & Regards,
Sharjeel

Regards,
Muhammad

sachin_namjoshi
Kilo Patron
Kilo Patron

use below in your workflow script

 

try {

       var et = new ErrorThrower(current);

       et.throwAnError(); 

} catch (e) {

       workflow.error('## Caught An Error ## ' + e); 

}