Errors and require

Use require for a condition that must hold; a failed requirement stops the run with an error.

require is an assertion for a condition the script depends on. This example succeeds because the score is positive. If the condition is false, lmscript reports the supplied message and exits; the troubleshooting page shows a reproduced failure and its exit code.

Script: errors-require.lms

score = 7;
require(score > 0, "score must be positive");
println("requirements passed");

Run it

lmscript examples/errors-require.lms

Output

requirements passed

Previous: Files and processes · Next: Typed host blocks

Try it: download examples/errors-require.lms, save it under examples/ in a writable working directory, then run the command above from that directory.