n$="something definite"

(which has its own report of 0 OK, 0:1) and:

CONTINUE

you will find that you can use n$ as input data without any trouble.

In this case CONTINUE does a jump to the INPUT command in line 110. It disregards the report from the LET (implied in this case) statement because that said OK, and jumps to the command referred to in the previous report, the first command in line 110. This is intended to be useful. If a program stops over some error then you can do all sorts of things to fix it, and CONTINUE will still work afterwards.

As we said before, the report L BREAK into program is special because after it, CONTINUE does not repeat the command where the program stopped.

We've seen so far programs where execution jumps to the beginning with no graceful way of ending the program. What we're producing are called never-ending loops and are some of the great pitfalls a programmer can fall in. There are some cases where execution cannot be stopped (if for example we have disabled error reporting) or the BREAK key is inhibited. In these cases we have to provide with either a clear exit path to the program, or use a special keyword that ends a program prematurely and that keyword is STOP. Let's modify our polite program to be as follows:

100 REM this polite program
    remembers your name
110 INPUT n$
120 PRINT "Hello ";n$;"!"
130 STOP

and then give RUN. After we enter our name and the computer greets us, we'll get a 9 STOP statement, 130:1 report indicating we exited the program forcibly by the STOP command on line 130. We could have left line 130 out entirely and the program would have terminated with a 0 OK, 120:1 which would have indicated a proper program termination.
In general, it's a good idea to provide exit paths in situations where the program may end up in a never-ending loop; NextBASIC provides us with such facilities as we're going to see further on.

Error trapping

As we saw above, NextBASIC can occasionally generate error reports whether we have inadvertently caused them ourselves or because something went wrong. Sometimes we need our program to stop execution and other times we want it to recover from the error and continue (as it is the case above where we gave the CONTINUE command). For these cases, NextBASIC provides us with the ON ERROR command.

This can intercept (trap) any error report (except 0 OK which is not considered an error) thus allowing your programs to recover from expected error conditions.

Turning on error trapping is as simple as:

ON ERROR statementlist

This will cause the statements contained in statementlist after the ON ERROR command to be executed whenever an error report would normally have been displayed. Note that this command must be part of a program and cannot be entered as a direct command.

To turn off error-trapping again, just use ON ERROR on its own.


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.