next | previous | forward | backward | up | top | index | toc | home
Macaulay2 > The Macaulay2 language > error handling > error

error -- deliver error message

Synopsis

Description

error s causes an error message s to be displayed.

The error message s (which should be a string or a sequence of things which 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.