error(a, b, ...[,format:Fmt or nsig:m, header:F, labels:F, missing:missStr, zero:zeroStr, macroname:F]), CHARACTER scalars Fmt, missStr and zeroStr, integer m > 0 |
error() is almost identical to print(). It differs in ways which make it useful for reporting errors recognized in a macro. (i) Use of error() immediately terminates execution of the current line or macro. (ii) error("Oops!") will print "ERROR: Oops!", where "Oops!" is a single quoted string or CHARACTER scalar that does not start with "ERROR:" or "WARNING:". When the message starts with "ERROR:" or "WARNING:" error() prints it unchanged. (iii) In macro mymacro(), say, error("Oops!") prints "ERROR: Oops! in macro mymacro". To avoid appending the macro name when using error() in a macro, use keyword phrase 'macroname:F'. This is helpful when the error message itself contains the macro name is in error("argument 2 to mymacro >= 1",macroname:F) Example: Cmd> for(i,run(nrows(x))){if(x[i] >= 0){y[i] <- sqrt(x[i]);;}else{ error("attempt to take square root of number < 0")}} This will terminate the loop on the first x[i] < 0. The message printed will actually be "ERROR: attempt to take square root of number < 0". See also topics print(), write(), paste(), 'macros', 'macro_syntax', 'for', 'if'.