I'm new to this aspect of error detection, so bare with me.
I have a program that needs to read some data from disk into a data structure. I want to be able to catch a file error such as reading beyond the end of the file, etc, so I thought I could put the ReadShort()s/ReadLong()s, etc inside a Try/Catch block and I could nab an error before it causes major problems. Take a look at the following test code:
The third and fourth Readxxxx() lines simply return zero (which I suppose could be handy in some situations), so how can I distinguish between an error zero and a legitimate value of zero read from the file?
According to the docs, if ReadShort() etc can not read enough data, they throw a TStreamReadException error. So how do I 'catch' that error and act accordingly?
Thanks,
Russell
I have a program that needs to read some data from disk into a data structure. I want to be able to catch a file error such as reading beyond the end of the file, etc, so I thought I could put the ReadShort()s/ReadLong()s, etc inside a Try/Catch block and I could nab an error before it causes major problems. Take a look at the following test code:
t:TStream = WriteStream("testfile.bla") WriteLong(t,20000) WriteLong(t,30000) CloseStream(t) Try u:TStream = OpenStream("testfile.bla") a:Long = ReadLong(u) b:Long = ReadLong(u) c:Long = ReadLong(u) ' Does not cause an error! d:Long = ReadLong(u) ' Neither does this! Catch err:TStreamReadException If err <> Null Then End ' This line is never executed EndTry Print a Print b Print c Print d CloseStream(u)
The third and fourth Readxxxx() lines simply return zero (which I suppose could be handy in some situations), so how can I distinguish between an error zero and a legitimate value of zero read from the file?
According to the docs, if ReadShort() etc can not read enough data, they throw a TStreamReadException error. So how do I 'catch' that error and act accordingly?
Thanks,
Russell