Steve Drain View profile More options 22 Feb 1999, 08:00 Newsgroups: comp.sys.acorn.programmer From: Steve Drain Date: 1999/02/22 Subject: Re: RESTORE ERROR Reply to author | Forward | Print | Individual message | Show original | Report this message | Find messages by this author - Hide quoted text - - Show quoted text - Reuben Thomas wrote: > 10 LOCAL ERROR > 20 REPEAT > 30 ON ERROR LOCAL PRINT"Negative value" > 40 INPUT x > 50 PRINT "Square root of x = ";SQR(x) > 60 UNTIL x=0 > 70 RESTORE ERROR > Sure enough, if I put in > 65ERROR 1,"Test" > run the program and type "0" at the prompt, I get "Negative value" and the > loop is re-entered. This seems to give the lie to the statement that the > error status is restored automatically by UNTIL. > Am I missing something, or is the manual plain wrong on this point? Tricky, isn't it? LOCAL ERROR first: This stores the current error status (usually the address after the last ON ERROR statement) and is restored as the manual states. However, there is an ambiguity, because the automatic RESTORE ERROR only happens /on exit/ from the loop structure it was used in, not just the next exit keyword. In the above example the LOCAL ERROR is outside the REPEAT UNTIL structure. Now ON ERROR LOCAL: This creates a new error status, which persists until it is changed by another ON ERROR [LOCAL] or RESTORE ERROR, which may be automatic. It differs from ON ERROR principally in retaining the current nesting. As you see, the two usages are independent, although they are probably best used together. At line 65 in the above example the current error status is from the ON ERROR LOCAL at line 30, which is where the ERROR 1 statement jumps to. As this enters the REPEAT UNTIL structure after the REPEAT, it has a knock on effect. You will find that entering /any/ value will cause a "Not in a REPEAT loop" error at UNTIL, which will be reported as "Negative value". The global error status is not restored until line 70. The effect you were expecting would be got from 10 REPEAT 20 LOCAL ERROR 30 ON ERROR LOCAL PRINT"Negative value" 40 INPUT x 50 PRINT "Square root of x = ";SQR(x) 60 UNTIL x=0 65 ERROR 1,"Test" PS I have just seen SW's reply. I don't think this conflicts and may add a little. -- ; ,', Steve Drain. Kappa http://www.users.zetnet.co.uk/kappa/ ;,' Basil: share BASIC libraries RFSFiles: add/remove files in Resources ;', ,; ',,