R. T. RUSSELL
BBC BASIC (Z80) Manual
Annex C to
BBC BASIC (Z80)
* Not applicable to BBC BASIC (Z80)
Strictly speaking 'Bad program' does not have an error code. It leaves
ERR and
ERL unchanged.
BBC BASIC (Z80)'s error messages and codes are briefly explained below
in alphabetical order.
Before BBC BASIC (Z80) calculates trigonometric functions (sin, cos,
etc) of very large angles the angles are reduced to +/-
PI radians. The
larger the angle, the greater the inaccuracy of the reduction, and
hence the result. When this inaccuracy becomes unacceptable, BBC BASIC (Z80)
will issue an 'Accuracy lost' error message.
This error indicates that too many or too few arguments have been
passed to a procedure or function or an invalid formal parameter has
been used. See the sub-section on
Procedures and Functions.
This error indicates that a procedure or function has been incorrectly
called, for example if there is a space after the PROC or FN.
PROC test
This error occurs when a command name is not recognized as a valid
BBC BASIC (Z80) command. Star commands which are unknown to BBC BASIC (Z80)
are passed to the Operating System. If the command is not recognised, an
untrappable 'Bad command or file name' error occurs.
Arrays must be positively dimensioned. In other words, the numbers
within the brackets must not be negative. This error would be produced
by the following example.
DIM table(20,-10)
(BBC BASIC version 5 or later only)
An EXIT statement was encountered when not inside a loop of the specified kind:
REPEAT
EXIT WHILE
UNTIL FALSE
The variable in a
FOR...NEXT
loop must be a numeric variable. If
you use a constant or a string variable this error message will be
generated. For example, the following statements are not legal.
20 FOR name$=1 TO 20
20 FOR 10=1 TO 20
Hexadecimal numbers can only include the characters 0 to 9 and A to F;
similarly binary numbers can only contain the digits 0 and 1. If
you try to form a hexadecimal or binary number with other characters this error will
occur. For example:
n = &OF
n = %21
(in the first example a letter O was used where the figure 0 was intended).
This error is generated if a path name exceeds 64 characters in length.
From time to time BBC BASIC (Z80) checks to see that the program in memory
is of the correct format (See
Annex E). If it is unable to follow
the program from the start to the 'program end marker' it will report
this untrappable error. The error can be caused by a read error,
by only loading part of the program or by overwriting part of the
program in some way. (Machine code programmers beware.) Without a
full understanding of how a program is stored in memory, there is
little you can do to recover a bad program.
File names in 'star' commands may optionally be enclosed in quotes. This
error will occur if the quotes are unmatched. The following example
would give rise to this error.
*SAVE "GRAPHS
If you try to access an element of an array less than zero or greater
than the size of the array you will generate this error. Both lines
20 and 30 of the following example would give rise to this error message.
10 DIM test(10)
20 test(-4)=20
30 test(30)=10
This error occurs when BBC BASIC (Z80) thinks it should be accessing
an array, but does not know which one.
BBC BASIC (Z80) has been unable to find a
FOR statement corresponding
to the NEXT statement.
This error is generated by the filing system. It occurs if you
try to use a channel which has not been opened, possibly because you
are using the wrong channel number.
This error will occur if the file(s) specified cannot be closed for any reason.
(BBC BASIC version 5 or later only)
This error is generated if BBC BASIC encounters a
RESTORE DATA statement but is unable to match it
with a corresponding LOCAL DATA statement.
This can happen as a result of jumping out of a loop in the meantime.
Note that when LOCAL DATA is used inside a FOR...
NEXT, REPEAT...
UNTIL or WHILE...
ENDWHILE loop, or inside a user-defined
function, procedure
or subroutine, the data pointer is automatically
restored on exit (there is no need to use RESTORE DATA).
This error will be generated if:
- There is insufficient room for an array when you try to
dimension it.
- An attempt has been made to reserve a negative amount of
memory. For example,
DIM A% -2
This error will occur if an attempt is made to create more files
than the device or directory has capacity for.
This error will occur if there is insufficient room on the storage device for
the data/program being written.
Mathematically, dividing by zero gives an infinitely large answer. The
computer is unable to understand the concept of infinity (it's not
alone) and this error is generated. If there is any possibility that
the divisor might be zero, you should test for this condition before
carrying out the division. For example:
200 IF divisor=0 THEN PROC_error ELSE...
This error is generated by pressing the <Esc> key. You can trap this,
and other errors, by using the
ON ERROR GOTO statement.
The EXP function is unable
to cope with powers greater than 88. If
you try to use a larger power, this error will be generated.
During renumbering, BBC BASIC (Z80) tries to resolve all line numbers
referred to by
GOTO and
GOSUB statements. Should it fail, it will
generate a 'Failed at nnn' error, where nnn is the
RENUMBERED line
which contains the unresolved reference.
The following example:
100 REM Demonstration renumber fail program
110 GOTO 250
120 END
would renumber as:
10 REM Demonstration renumber fail program
20 GOTO 250
30 END
and generate the error message 'Failed at 20'.
This error will be generated if you try to rename a file and a file
with the new name already exists.
This error will occur if you try to
LOAD,
*LOAD or
CHAIN a file which
does not exist.
A program line is too long to be represented in BBC BASIC (Z80)'s internal
format.
Logarithms for zero and negative numbers do not exist. This error
message will be generated if you try to calculate the log of zero
or a negative number or raise a negative number to a non-integer power.
This error message is generated if BBC BASIC (Z80) was unable to find
a comma where one was expected. The following example would give
rise to this error.
20 PRINT TAB(10 5)
This error message is generated if BBC BASIC (Z80) was unable to find
a double-quote where one was expected. The following example would
give rise to this error.
10 name$="Douglas
This error message is generated if BBC BASIC (Z80) was unable
to find a closing bracket where one was expected. The following example
would give rise to this error.
10 PRINT SQR(num
This error will occur if BBC BASIC (Z80) is unable to find a hash symbol
(a pound symbol on some computers) where one was expected. The following
example would cause this error.
CLOSE 7
(BBC BASIC version 5 or later only)
This error is generated if BBC BASIC cannot locate an
ENDCASE statement to terminate
the current CASE statement.
(BBC BASIC version 5 or later only)
This error is generated if BBC BASIC cannot locate an
ENDIF statement to terminate
the current multi-line IF ...
THEN statement.
This error message will be generated if BBC BASIC (Z80) encounters a
FOR...NEXT
loop with the TO part missing.
This error will be generated if BBC BASIC (Z80) is unable to make any
sense at all of the input line.
This error is generated by the assembler
if, during the first pass of an assembly
(OPT 0, 1, 4, 5, 8, 9, 12 or 13), a label is
found to have an existing non-zero value. This is most likely to be
caused by the same label being used twice (or more times) in the
program.
This error message will occur if BBC BASIC (Z80) attempted to calculate
the square root of a negative number. It is possible for this error
to occur with
ASN and
ACS as well as
SQR.
90 num=-20
100 root=SQR(num)
This error message will be generated if BBC BASIC (Z80) finds a
RETURN
statement without first encountering a
GOSUB statement. (See the
sub-section on Program Flow Control.)
This untrappable error indicates that all the computer's available
memory was used up whilst a program was running. This error may occur
as a result of numerous assignments to string variables, as in a string
sort. See the explanation of
String Variables and Garbage in the
Variables sub-section for details.
When BBC BASIC (Z80) encounters a name beginning with
FN or
PROC it expects
to be able to find a corresponding function or procedure definition. This
error will occur if such a definition does not exist.
This error will occur if BBC BASIC (Z80) tries to
GOTO,
GOSUB,
TRACE or
RESTORE to a non-existent line number.
Variables are brought into existence by assigning a value to them
or making them
LOCAL in a function or procedure definition. This
error message will be generated if you try to use a variable on the
right-hand side of an assignment or access it in a
PRINT statement
before it has been created. As shown below, you can create variables
very simply.
10 count=0
20 name$=""
If BBC BASIC (Z80) encounters an end of function without calling a function
definition, this error message will be issued. If you forget to put
multi-line function definitions out of harm's way at the end of the
program you are very likely to get this error message. (See the sub-section
on Procedures and Functions.)
If you try to define a variable as
LOCAL outside a procedure or function,
this error message will be generated. If you forget to put multi-line
function definitions out of harm's way at the end of the program you
are very likely to get this error message. (See the sub-section on
Procedures and Functions.)
This error message indicates that BBC BASIC (Z80) has found a
NEXT statement
without first encountering a FOR statement.
If BBC BASIC (Z80) encounters an
ENDPROC without performing (calling)
a procedure definition, this error message will be issued. If you
forget to put multi-line procedure definitions out of harm's way at
the end of the program you are very likely to get this error message.
(See the sub-section on Procedures and Functions.)
This error message indicates that BBC BASIC (Z80) has found an
UNTIL
statement without first encountering a
REPEAT statement.
(BBC BASIC version 5 or later only)
This error message indicates that BBC BASIC (Z80) has found an
ENDWHILE statement
without first encountering a WHILE statement.
This error will occur if a number is entered or calculated which is
too big for BBC BASIC (Z80) to cope with.
(BBC BASIC version 5 or later only)
This error is generated if the keyword OF is not
the last thing on the line in a CASE statement.
OF cannot even be followed by a REMark.
(BBC BASIC version 5 or later only)
This error is generated if BBC BASIC encounters a
RESTORE ERROR statement but is
unable to match it with a corresponding
ON ERROR LOCAL statement. This can be caused by
having 'jumped out of a loop' in the meantime (see the
sub-section on Program Flow Control
for more details).
This error will be generated if, in a simple
ON GOTO/GOSUB/PROC statement,
the control variable was less than 1 or greater than the number of
entries in the ON list. These exceptions can be trapped in ON GOTO/GOSUB/PROC
statements by using the
ELSE option. The first example below will
generate an 'ON range' error, whilst the second is correct.
10 num=4
20 ON num GOTO 100,200,300
10 num=4
20 ON num GOTO 100,200,300 ELSE 1000
This error will be reported if the
ON...GOTO statement was misformed. For
example, the following statement is not legal. (Refer to the keyword
ON for details of legal statements.)
20 ON x TIME=0
If your program tried to read more items of data than there were in
the data list, this error will be generated. You can use
RESTORE
to return the data pointer to the first data statement (or to a particular
line with a data statement) if you wish.
This assembly language error
will be reported if you tried to perform
a relative jump of more than +127 or -128 bytes or you used a
16 bit port address when only an 8 bit address is allowed.
When BBC BASIC RENUMBERs
a program it has to build a cross-reference table of line numbers. If there
is insufficient memory to hold this table, the 'RENUMBER space' error
results. In this case you can still renumber the program using the
RENUMBER.COM utility program supplied.
This error message will be issued if you try to renumber a program
or enter
AUTO with a step size of 0.
AUTO with a step size of more than 255 will work, but it will be
evaluated MOD 256.
You will get this error message if your program tries to generate
a string which is longer than 255 characters.
A command was terminated incorrectly. In other words, the first part
of the command was recognized, but the rest of it was meaningless
or incomplete. Unlike
Mistake, BBC BASIC (Z80) was able to recognise
the start of the command.
This error will occur if you try to open more than seven files at any one time.
This error indicates that a number was encountered when a string was
expected and vice-versa. Don't forget that this can occur if the
actual parameters and the formal parameters for a function or procedure
do not correspond. (See sub-section on
Procedures and Functions for
details of parameter passing to functions and procedures.)
Error number 255 is reserved for errors with an unknown cause, such as those
thrown by the Operating System (such an error may be reported as 'CP/M Error').
© Doug Mounter and
Richard Russell 2025