Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

ER

Keyword Abbreviation Token (hex) Version(s) Classification
ER none 45 52 3.5, 4.7+ Reserved variable
Note the 'token' is really the character codes of the keyword.

  Syntax  
ER
 
Returns Type Value(s) Note(s)
errorNumber Integer
varies
 
 
  Purpose  
Error trapping (and debugging); return the most recent errorNumber.
 
  Remarks  
This returns the most recent errorNumber.  In BASIC versions 3.5 and 7.0, a value of -1 indicates no previous error.  In version 4.7 a value of 127 indicates no previous error.  Assuming there was a last error, a string description corresponding to the errorNumber may be obtained with ERR$; see that function for a list of errorNumbers and error messages (these vary by version number, sometimes drastically).
 
The value is set to "no error" on power-up and whenever CLR is executed (performed as a part of RUN and, in direct mode, (D)LOAD).  The value is also (usually) set when an error occurs.  Exceptions are the special (untrappable) errors of INPUT: EXTRA IGNORED and REDO FROM START.
 
ER is typically used in a program's TRAP handler to determine what kind of error occured.  Because the line number of the error is also available (see EL), the ER value may not be needed (i.e., the error can be inferred by the programmer based on which line has the error).  It may occassionaly be useful in direct mode while debugging in order to recall the last error (for example if a displayed error message scrolls off the screen while listing program lines).
 
Like all BASIC variables, only the first two characters of the name are significant.  So you may also append extra characters; you could use the name ERRNUM if you prefer (note the -RNUM would be superfluous).
 
Like most reserved variables, a SYNTAX ERROR will be generated if you attempt to assign a value to ER.
 
In version 4.7, ER is only valid in a program.  In direct mode it returns 127 (no error).
 
Examples (version 3.5 and 7.0):
PRINT ER
-1

READY.
JUMP OF A CLIFF

?SYNTAX ERROR
READY.
PRINT ER
 11

READY.
 
  Compare With  
 
  See Also  

© H2Obsession, 2014
Comments