From: Jim Freeze Date: 2002-07-09T05:34:12+09:00 Subject: Re: How to determine EOF with sysread? On Mon, Jul 08, 2002 at 10:05:34PM +0900, Peter Hickman wrote: > Austin Ziegler wrote: > > >On Mon, 8 Jul 2002 14:47:25 +0900, Sean Chittenden wrote: > > > >>>Thanks all for the answers. Does it strike anyone as bad practice > >>>to use a rescue for control flow? I thought a more explicit test > >>>method would have been provided. > >>> > >>My C roots tell me, yes, but my Ruby roots tell me no. Having an > >>exception thrown/caught is okay practice in Ruby. > >> > >It still seems wrong to me, since an end of file condition is an > >expected situation, not an exceptional situation. > > > >-- Austin Ziegler, austin@halostatue.ca on 2002.07.08 at 08.39.15 > > But eof is the exception when reading a file, because a read will > usually succeed. > This sort of thing is used a lot on VAXes (if they still exist) and > early mini / mainframe designs. > > I expect programs to have bugs, but I can't predict what and where or I > would have written the program differently. Therefore they are > exceptions even though they are expected. > You have a point, but everyone that provided code to answer my question assumed there was no errors in reading. In other words, if we use the exception to catch an EOF, we have to be able to distinquish it from a 'real' error. So, if the file is 100 bytes, and it only reads fifty, I would like to know about it. Seems I would have to add some code to sum the bytes read and re-throw if the exception is caught before the end of the file is reached. -- Jim Freeze If only I had something clever to say for my comment... ~