Personal Computer News


Error-Handling On The Beeb

 
Published in Personal Computer News #065

Error-handling On The Beeb

One unfortunate consequence of the way that BBC Basic performs its error handling is that global values of procedure parameters - their values outside the procedure - may be affected after an error has been trapped.

Note that procedure parameters are normally local to the procedure. When a procedure call with parameters is made, the external values of the parameters are copied onto the Basic stack so that the parameter variables may be used as temporary local variables from the stack and the parameters are restored to their values prior to the procedure call.

This does not appear to occur when Basic detects an error. The parameters are left with the local values they had immediately prior to the error.

The following short listing should illustrate the problem. Run the program, delete line 80 (which generates a "No Such Variable" error) and then re-run.

The difference will be readily apparent. User-defined functions behave exactly the same.

10 ON ERROR GOTO 40
20 A=10:B=20:C=30
30 PROCmistake(A,B,C)
40 PRINT A,B,C
50 END
60 DEFPROCmistake(A,B,C)
70 A=1:B=2:C=2
80 DELIBERATE MISTAKE!
90 ENDPROC

No doubt the enterprising reader will find ways of putting this defect in Basic error handling to some use. It is as well to point out however that this could lead to more problems than it solves and would certainly never qualify as good programming practice.

W. J, Birtwistle, Blackpool, Lancashire

W. J. Birtwistle