Err

From Br Wiki
Jump to: navigation, search
ERR

The Err internal function returns the error code of the most recent error.

Comments and Examples

Program errors which are not anticipated can be handled by adding the following to any program.

00001 ON ERROR GOTO 99900
   o
   o
99900 PRINT "Unexpected Error Number";ERR
99910 PRINT "occurred at line number";LINE
99920 PRINT
99930 PRINT "Please record this information,"
99940 PRINT "and call your dealer at once!"
99950 PAUSE
99960 CHAIN "MENU"

ERR is also used in procedures to determine when commands are successful. In the following procedure, a PROTECT command is used to reserve a file on a multi-user system before attempting to rebuild the index for the file.

PROCERR RETURN
PROTECT CUSTOMER,RESERVE
PROCERR STOP
SKIP DONE IF ERR<>0
INDEX CUSTOMER CUSTOMER.KEY 1 4 REPLACE
:DONE
CHAIN "menu"

PROCERR RETURN does two important things in this procedure. It turns off normal system error processing so that the system will not stop or beep if an error occurs. Also, it resets ERR to zero. After PROCERR STOP reinstates normal error processing, the SKIP command checks ERR and branches to the label DONE if ERR is no longer zero.

Related Functions

Technical Considerations

  1. ERR is initialized to zero by the following: the RUN command, PROCERR RETURN command, CLEAR or CLEAR ALL commands and any other commands which clear memory.
  2. There are three cases where errors occur and ERR is not set. First, ERR is not changed when an ON error statement (or default) has set to IGNORE the error condition corresponding to this error. Second, when the error code is 4273 (topic not found in help file), the system does not set ERR or LINE so that an error in attempting to use the HELP$ function in an error trapping routine will not affect the ability to use RETRY or CONTINUE. Third, the value of ERR is not affected when an error occurs in an immediate statement which has been keyed in from the keyboard; the error code for this immediate statement is displayed correctly in the status line.
  3. Even when PROCERR RETURN is used in a procedure file to skip an error, the value of ERR is still set and can be tested with a SKIP command, such as SKIP 3 IF ERR=0
  4. ERR is affected by any error-causing string expression which is executed by a line-numbered EXECUTE statement.