Click Here To Go To The Your Computer Archive



Written By Joe Pritchard


Cover Art
Click Here To Enlarge Loading Screen

Loading Screen
Click Here To Enlarge Opening Screen

Opening Screen
Click Here To Enlarge Screenshot

Game Screenshot

Error Simulation

Joe Pritchard, Gelding, Nottingham

One problem that I keep coming up against when finishing off my Basic program is testing the error-trapping routines. Most of my programs are used by other people than myself, and so it's important that the programs respond to errors in a reasonably graceful fashion! For example, I often want to reprompt the user to try again if an error such as "No such file" has been generated.

The usual method I use to test such routines is to deliberately cause the error, by typing in a non-existent filename, for example. However, this technique is not always useful; it's hard to simulate a "Disc full" error with two short files on a disc!

Machines like the MSX computers have a command called ERROR which allows the programmer to simulate an error condition. This program adds a similar command, called *ERR to the BBC Micro. The syntax is *ERR n or *ERR variable name

where the value of n or the variable is the number of the error you wish to simulate. Thus *ERR 4 will simulate the Mistake error. The message "Simulated Error" will be printed to the screen as the Report, but ERR will be set to the value of n and ERL will be set accordingly.

The simulated error can be trapped by the Basic On Error trap, in which case the Report will not be printed but ERR and ERL will be set up properly, as mentioned above. The code is less than 256 bytes long, and so I keep it safely in page &A.

You might like to set up function keys to change the CLI vector to point to the new machine code and reset the CLI vector when the new command is no longer required. As an example, if the below line is part of your error trap:

1000 IF ERR=4 THEN PRINT"Ooops!!"

then executing a *ERR 4 somewhere in the program, with the On Error active, will result in "Ooops!!" being printed to the screen.