EndOfStream an Error???

Lex Spoon lex at cc.gatech.edu
Fri May 26 17:48:46 UTC 2000


"John W. Sarkela" <john_sarkela at 4thEstate.com> wrote:
> It would be necessary for this exception to define its default handler
> action to return nil. This would preserve the semantics of non-exception
> aware code while simultaneously making it  possible for exception aware
> code to trap the exception and handle it in new and novel ways.
> 

Hmm.  It seems to actually be more complicated.  Suppose you have a
filtering stream F which filters an underlying stream S.  Then you try
something like:


	[ x := F next ] on: EndOfStream do: [ F close.  ^stuff ].


Well, this is okay, except when you look at the implementation of
F>>next:

	next
		| a |
		a := S next.
		a ifNil: [ self cleanup.  ^nil ].
		^a + 1


This implementation is relying on the return-nil implementation, but
since an outer scope has set up an exception handler, the implementation
here is now going to miss its chance to do "self cleanup".

We should probably pick one method and stick with it.  Perhaps only the
most core of Stream classes should not use exceptions, if we are going
to make an exception-filled system.


By the way, a related problem lurking around is what #next: should do at
end-of-file.  Currently it varies on whether you get a smaller buffer,
or a buffer padded with nil's, or an error....  The behavior should be
defined if streams are to be substitutable for each other.

-Lex





More information about the Squeak-dev mailing list