Dealing with error messages

Post Reply
Geordie Phil
Posts: 2
Joined: Mon Sep 16, 2024 12:49 pm
My devices: iPad Pro
Flag: Great Britain

Dealing with error messages

Post 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?

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Dealing with error messages

Post 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.

Geordie Phil
Posts: 2
Joined: Mon Sep 16, 2024 12:49 pm
My devices: iPad Pro
Flag: Great Britain

Re: Dealing with error messages

Post by Geordie Phil »

Hi Henko,
That has solved my problem, thanks!

Post Reply