This is required if you wish to generate errors again (and you may wish to do so if you need to know what went wrong). The following example will display There was an error! and terminate with the 9 STOP statement error when line 20 is executed:

10 ON ERROR PRINT "There was
   an error!":ON ERROR:STOP
20 PRINT 5/0

ERROR [n]

To generate the last error that actually occurred (this does not need error-trapping to be turned off), just type the command:

ERROR

followed by ENTER. Assuming the program above, the following amendment will print the message but still give the correct Number too big report:

10 ON ERROR PRINT "There was
   an error!":ERROR
20 PRINT 5/0

Used with the optional parameter n, where n is a value between 0 and 3, ERROR can return the error code (for n=0), the line (for n=1), the statement (for n=2) and the memory bank where it occured (for n=3) – See Chapter 23 for details about memory banks. For example:

PRINT ERROR (1)

given after the example above would return 20. Moreover there's also:

ERROR$

which prints the error report rather than just the code. You could modify the example above to be:

10 ON ERROR PRINT "There was
   error! "; ERROR$:ON
   ERROR:STOP
20 PRINT 5/0

which will print the actual error report Number too big. You could then substitute STOP with a GO TO to the line of error handling code without having to halt execution of your program.

An additional way with which you can obtain details of the last error and store them away maybe for purposes of statistical analysis is using the following command:

ERROR TO codevar [, linevar, [statementvar, [bankvar]]]

This will store the error code in the numeric variable codevar, the line number in linevar, the statement number in statementvar and the bank number in bankvar (do not worry about what bank means for the moment). Note that you do not need to supply later variable names if you do not need the information, so all of these are valid:

ERROR TO e
ERROR TO e,l
ERROR TO e,l,s
ERROR TO e,l,s,b

ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.