Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF

277 An ELSE clause can be included at the end of ON GOTO and ON GOSUB to trap out of range values without causing an error. Thirdly: ON ERROR GOTO ON ERROR OFF If the computer detects an error in your program or in the disc drives or anything else that it can’t handle, then it produces an error. In other words it complains and stops. The complaint takes the form of a message on the screen - for example Too big . Sometimes it is vital that the computer looks after such situations without troubling the user. The statement ON ERROR GOTO 7000 ensures that if an error occurs the computer does not complain and does not stop.

Instead it goes to a section of program at line 7000 (in this case) which has been specially written to get the computer out of the mess it is in. This section of program may have to give the user instructions like Please enter a smaller number or it may be able to sort out the problem in some other way. How well this ‘error trapping’ works depends on the skill of the programmer in thinking of every possible thing that can go wrong. You will soon re-discover Murphy’s Law: ‘If anything can go wrong, it will.’ Good error handling is vital in all programs for use by non-specialists - and that means most people!

The statement ON ERROR OFF lets the computer deal with errors once again - cancelling the effect of ON ERROR GOTO . 40 ON ERROR GOTO 9000 Examples 50 ON ERROR PRINT "The computer is confused" 10 ON ERROR GOSUB 2000 Description A statement providing multiple options in changing the order of execution of a program, and error trapping.