Topic: APLX Help : Help on APL language : System Functions & Variables : ⎕ERS Error signalling
[ Previous | Next | Contents | Index | APL Home ]

www.microapl.co.uk

⎕ERS Error signalling


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:

  • If ERRORNUMBER is a positive integer associated with a standard APLX error message, the associated error message is signalled. See the section on Error Codes for a list of standard error numbers.
  • If the ERRORNUMBER is positive, but is not associated with a standard error message, an UNKNOWN ERROR TYPE is signalled.
  • Negative ERRORNUMBERs cause an error to be signalled but no message to be displayed.
  • If ERRORNUMBER is 0, no error is signalled and ⎕ER, ⎕ET, ⎕ERM and ⎕EM are reset.
  • If ERRORNUMBER is an empty numeric vector, the function has no effect. No error is signalled.

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

Topic: APLX Help : Help on APL language : System Functions & Variables : ⎕ERS Error signalling
[ Previous | Next | Contents | Index | APL Home ]