The nomadic system function ŒERS is used to 'signal' errors to a calling function. The calling function is halted unless it is error trapped. ŒERS can be used with one or two arguments:
ŒERS ERRORNUMBER ERRORMESSAGE ŒERS ERRORNUMBER
The ERRORNUMBER may be a vector of numbers, but the first is used as the argument. The ERRORNUMBER can be any integer, or an empty vector. The error message associated with the first number in the right argument is displayed, the calling function is halted and the first number of ŒLER (Line Error Report) is set to this number. The exact behavior depends on the value of ERRORNUMBER:
An error message can be included as the left argument. If present, this is displayed instead of the normal error message associated with this number.
For example, an attempt to divide by zero normally generates:
2÷0 DOMAIN ERROR 2÷0 ^
A function DIVIDE can be written which 'signals' an attempt to divide by zero, rather than stopping:
’ R„A DIVIDE B [1] 'ATTEMPT TO DIVIDE BY ZERO' ŒERS (B=0)/8 [2] R„A÷B [3] ’ 2 DIVIDE 0 DOMAIN ERROR 2 DIVIDE 0 ^
and this function can itself be used within other error trapped functions:
’ TEST;X [1] X„ŒERX ERR [2] START:'ENTER TWO NUMBERS ' [3] DATA„2†Œ ©MAKE SURE WE HAVE 2 NUMBERS [4] 'THE DIVISION IS:' [5] DATA[1] DIVIDE DATA[2] [6] …0 [7] ERR:…(8¬1†ŒLER)/0 ©NOT ONE OF OUR ERRORS [8] 'ATTEMPT TO DIVIDE BY ZERO, TRY AGAIN' [9] …START [10] ’
TEST ENTER TWO NUMBERS Œ: 4 2 THE DIVISION IS: 2 TEST ENTER TWO NUMBERS Œ: 4 0 ATTEMPT TO DIVIDE BY ZERO, TRY AGAIN Œ: 4 4 THE DIVISION IS: 1
The use of a negative argument to ŒERS suppresses printing of the error message.
’R„A DIVIDE B [1] ŒERS(B=0)/¯8 [2] R„A÷B ’ 1.53.19 05/28/90 3 DIVIDE 0 3 DIVIDE 0 (No error message shown) ^ ŒLER (ŒLER set to ¯8) ¯8 0 ŒET (ŒET set to 0 1) 0 1 ŒERS 0 (Use of ŒERS 0 to reset error numbers) ŒLER 0 0 ŒET 0 0