Page 1 of 1

Dealing with error messages

Posted: Mon Sep 16, 2024 1:26 pm
by Geordie Phil
As part of a program I am writing I wish the program to keep running, and deal with any error messages within the program. One particular error is when I input from a file and reach the end of the file, I get a massage that there is no data. Is there a way of doing this?

Re: Dealing with error messages

Posted: Mon Sep 16, 2024 8:18 pm
by Henko
Hi Geordie,

As far as i know, SB has no error trapping like "on error goto.....".
In the example mentioned by you the error may be evaded by using something like the following snippet:

f$="Data/messages.txt" ! i=0
if not file_exists(f$) then return
while data_exist(f$)
i+=1 ! file f$ input .mess$(i)
end while
n_items=i

Where the exixtence of the file is first checked, and then data is read until the end of the file is reached; no error occurs.

Re: Dealing with error messages

Posted: Tue Sep 17, 2024 6:07 pm
by Geordie Phil
Hi Henko,
That has solved my problem, thanks!