EndOfStream an Error???

Michael Rüger m.rueger at acm.org
Wed May 24 09:45:12 UTC 2000



"Raab, Andreas" wrote:

> Just wondering: Who came up with the idea that EndOfStream is an error?!
> There's a definite notion in ST80 that ReadStream>>next returns nil if there
> are no more elements so that this can hardly count as an error, can it?!

Well, which is not quite helpful if you have a stream that actually
*can* return nil as the next value ((ReadStream on: (Array new: 1))
next).

> You'll see the effect (since the error handler in PasteUps drawing method is
> intended to catch Errors rather than an end of stream notification). Any
> ideas of how to fix this?!

This problem has been annoying in OW/VW as well, where they used an
exception to signal end of stream as well.
There are several ways to work around it:
- use a notification or any other non error exception (as suggested by
Paul)

- use the UnhandledException handler to provide a nil return value if no
handler for the end-of-stream is installed. Which in turn can drive you
nuts if you forget to use a eof handler but have another exception
handler installed (at least I remember being bitten by this in VW quite
often)

- use a combination of the two: 
  signal eof notification, if not catched, return nil

I vaguely remember that the atEnd check was quite expensive on some
streams (again in VW), so the usual "[s atEnd] whileFalse" slowed things
down quite a bit. And then you might notice the eof only until the next
read.

Michael




-- 

+------------------------------------------------------------+
| Michael Rueger    m.rueger at acm.org       ++49-391-733 9808 |
+------------------------------------------------------------+





More information about the Squeak-dev mailing list