Abort script nicely

Solved1.65K viewsScripting


In my script, I check the user input, and in case I find something wrong, I want to inform the user (using “Alert()” to send a custom message) and then quit the script nicely. I did not find anything other than “assert 1==0”, but this gives another annyoing pop-up to the user. Using “System.exit(0)” exits the script, but closes Quantrix as well, which is not the idea.

Any ideas?

Thanks, Gilbert

Gilbert Selected answer as best November 29, 2022

Hi Gilbert,

Try “return”

if([whatever check])


Gilbert Selected answer as best November 29, 2022

Sorry Lyndsey,

return DOES work IF you use it correctly!!!

Return does not abort the script, but just the exits the current code bloc, NOT the entire script, as an unfamiliar user like me might expect. Also, you can not return from “each” – what I tried.

So I do just set a boolean “ErrorFlag” to true, get out of the current block, and testing ErrorFlag before entering the next one … and return there again. In my case of the “each” is not time-critical, I do finish the each, but just do not execute more inside code (putting it into a “if (!ErrorFlag)”).

So yes, return works, if done correctly :-).

Thanks for your help, Lyndsey!

Gilbert Edited answer December 11, 2022

I also did try “return”, unfortunately, this does not work (e.g. the script just continues).


Gilbert Answered question November 29, 2022

Latest Questions