Proper script writing: throwing errors within UDFs
Posted: 30 Apr 2015 18:29
Today I just tested the waters when it comes to UDFs, and I'd like to know what's the proper way to throw errors in an UDF.
First, a little observation: something like thisthrows an error at formatdate() in the "script console", and then continues setting the variable to nothing.
TheQwerty suggests using assert, which takes an optional "continue" flag. Setting it it's like no "real" error is thrown at all, because the UDF continues. Not setting the "continue" flag terminates the whole script instead.
Then there's end, which is more granular because it allows to abort the UDF without terminating the whole script, however it throws a warning with a popup window, which is not consistent with a "genuine" function error.
So, how can I throw an error in a UDF which
-makes the script console pop up
-aborts the rest of the UDF
-continues executing the rest of the calling script,
much like an XY function?
First, a little observation: something like this
Code: Select all
$x = formatdate(gttw3tw);TheQwerty suggests using assert, which takes an optional "continue" flag. Setting it it's like no "real" error is thrown at all, because the UDF continues. Not setting the "continue" flag terminates the whole script instead.
Then there's end, which is more granular because it allows to abort the UDF without terminating the whole script, however it throws a warning with a popup window, which is not consistent with a "genuine" function error.
So, how can I throw an error in a UDF which
-makes the script console pop up
-aborts the rest of the UDF
-continues executing the rest of the calling script,
much like an XY function?