Local error trapping differences

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Local error trapping differences

Post by Richard Russell »

This may well have been discussed previously, but I can't find it on a quick search (the words 'on', 'error' and 'local' are apparently too common for the forum to allow me to search for them!). So apologies if you've seen it before.

BBC BASIC version 5 or later - that is to say Acorn's ARM BASIC V & VI, 6502 Advanced BASIC, BB4W, BBCSDL, BBCTTY, Brandy BASIC and BBC BASIC (Z80) v5 - accepts the LOCAL ERROR and ON ERROR LOCAL statements. These allow the current error-handling status to be 'temporarily' changed and later restored using RESTORE ERROR.

However these statements operate slightly differently in the different versions of BASIC, as follows:

Code: Select all

---------------------------------------------------------------------------------------------------------
|                |        Acorn BASICs        |       Brandy BASIC         |        RTR's BASICs        |
---------------------------------------------------------------------------------------------------------
| LOCAL ERROR    | Saves both the ON ERROR    | Saves only the ON ERROR    | Does nothing (is ignored). |
|                | destination & the previous | destination to the stack.  |                            |
|                | nesting level to the stack.|                            |                            |
---------------------------------------------------------------------------------------------------------
| ON ERROR LOCAL | Records the current nesting| Saves the previous nesting | Saves both the ON ERROR    |
|                | level then sets up a new   | level to the stack, records| destination & the previous |
|                | ON ERROR destination.      | the current nesting level  | nesting level to the stack,| 
|                |                            | then sets up a new         | records the current nesting| 
|                |                            | ON ERROR destination.      | level then sets up a new   |
|                |                            |                            | ON ERROR destination.      |
---------------------------------------------------------------------------------------------------------
The important thing to note is that if used as a pair the effect is identical in the three implementations, but if LOCAL ERROR or ON ERROR LOCAL is used individually the effect is different. This is rarely an issue in practice, but is worth bearing in mind.

Note that because LOCAL ERROR is ignored by my BASICs it may be omitted, but if you want your program(s) to be compatible with other versions of BBC BASIC it should be included.