Macaulay2 » Documentation
Packages » Macaulay2Doc > The Macaulay2 language > error handling > error
next | previous | forward | backward | up | index | toc

error -- deliver error message



error s causes an error message s to be displayed.

The error message s (which should be a string or a sequence of things that can be converted to strings and concatenated) is printed. Execution of the code is interrupted, and control is returned to top level. Here is an explicit example showing how this command is used:
exampleCode = p -> (
     if not isPrime p
     then error "expected a prime integer";
     if p == 2
     then error "expected an odd prime";
     lift((p+1)/2, ZZ)

Eventually we will have a means of ensuring that the line number printed out with the error message will have more significance, but currently it is the location in the code of the error expression itself.

If the error message begins with a hyphen, then the word "error" will not be inserted into the error message.

For the programmer

The object error is a function closure.