error
Builtin index · REPL & diagnostics
error(msg)
Input: msg · Output: no output
What it is
Takes one argument, msg (a string, typically built with {...} interpolation), and raises an EvalError carrying that message. Never returns normally — control passes to the nearest enclosing try/catch, where the caught exception object exposes the string as .message; uncaught, it aborts the script.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
error(msg) | msg stringnot documented yet | no output | Never returns normally — control passes to the nearest enclosing try/catch, where the caught exception object exposes the string as .message; uncaught, it aborts the script. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
function check_positive(x)
if x < 0
error("check_positive: x must be >= 0, got {x}")
end
return x
end
try
check_positive(-3)
catch err
print("caught: {err.message}")
end
from repl-diagnostics
How it works
error(msg) raises — an ordinary EvalError, catchable by an enclosing try/catch (§18.B). warn(msg) is non-fatal.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.