Dealing with error messages
-
- Posts: 2
- Joined: Mon Sep 16, 2024 12:49 pm
- My devices: iPad Pro
- Flag:
Dealing with error messages
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?
-
- Posts: 814
- Joined: Tue Apr 09, 2013 12:23 pm
- My devices: iPhone,iPad
Windows - Location: Groningen, Netherlands
- Flag:
Re: Dealing with error messages
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.
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.
-
- Posts: 2
- Joined: Mon Sep 16, 2024 12:49 pm
- My devices: iPad Pro
- Flag:
Re: Dealing with error messages
Hi Henko,
That has solved my problem, thanks!
That has solved my problem, thanks!