[Next] [Prev] [Right] [____] [Up] [Index] [Root]
error statement

error statement

There are two statements in Magma for the reporting of errors. The syntax of the simple error-statement is:

error EXPRESSION, ..., EXPRESSION;

and the syntax of the error-if statement is:

error if PREDICATE, EXPRESSION, ..., EXPRESSION;

These statements may be used inside the statement body of a function or procedure expression. They cannot be used within a func< > or proc< > constructor.

If Magma encounters a simple error-statement when executing a function call or procedure call, or if it encounters an error-if statement where the PREDICATE evaluates to true, then it prints the values of EXPRESSIONs as output. After that, Magma breaks out of the call.

If this happens in a function call, no values are returned from the function. (This is also true for calls to intrinsic functions that result in errors.)

Example

> // simple error-statement
> Stars := procedure(n)
procedure> if n notin [0..80] then
procedure|if> error "Runtime error in 'Stars': Argument 1 (", n,                 
procedure|if|error> ") not in range [0..80]";
procedure|if> else print "*"^n; 
procedure|if> end if;
procedure> end procedure;
> Stars(15);           
***************
> Stars(81);
Runtime error in 'Stars': Argument 1 ( 81 ) not in range [0..80]

> // equivalent procedure, using error-if > Stars := procedure(n) procedure> error if n notin [0..80], procedure|error> "Runtime error in 'Stars': Argument 1 (", n, procedure|error> ") not in range [0..80]"; procedure> print "*"^n; procedure> end procedure;

> // same output

[Next] [Prev] [Right] [____] [Up] [Index] [Root]