Quit argument error
Hi Guys,
I get a Quit argument not allowed error in an if block how can I fix this?
Thanks
Comments
Use 'Return' instead: https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_creturn
In general, if you're trying to exit a method and return a value to the caller, 'Return' is the best way to do that, as 'Quit' also has functionality for control flow (such as breaking out of WHILE loops).
The Quit command is quitting the if statement therefore no value is allowed.
Clean code is not to have multiple places that quit with value, in long code it is difficult to track. Therefore a nice structure could be:
Ser result=1
If [condition] { ... set result=0 }
else { ... set result=1 }
Quit result
The problem is NOT the QUIT in an IF statement, the problem is, using a QUIT WITH ARGUMENT in a TRY/CATCH statement.