Re: Exception Names
- From: "Mike Schilling" <mscottschilling@xxxxxxxxxxx>
- Date: Fri, 27 Mar 2009 12:04:03 -0700
Owen Jacobson wrote:
On 2009-03-27 11:29:24 -0400, "Mike Schilling"
<mscottschilling@xxxxxxxxxxx> said:
Lew wrote:
rossum wrote:
On Fri, 27 Mar 2009 11:58:20 +0000, Tom Anderson
<twic@xxxxxxxxxxxxxxx> wrote:
InputStream.read should throw an EOFException instead of returningIt may bee goofy but it is very likely to be a whole lot faster.
-1 at the end of a stream. Checking return values for special
values is goofy C bull*** that we shouldn't be doing in the 21st
century.
Throwing and catching an exception is probably going to be a lot
slower than checking the return value.
Besides, there's nothing exceptional about reaching the end of a
stream. One would venture to say that one nearly always reaches the
end of a stream, *unless* something exceptional happens.
Right; the most Java-ish thing would be for Streams to be
iterator-like:
while (stream.hasNext())
{
char c = stream.next();
}
or even
for (char c: stream)
{
}
Writing a StreamIterable adapter is fraught with annoying, though.
Consider: both .next() and .hasNext() *potentially* perform IO,
depending on whether you've already called hasNext when calling next.
And you can't throw any checked exceptions.
It's no worse than, say, creating a Collection backed by a disk file or
database. You have to wrap the exceptions with RuntimeExceptions. What I'm
not seeing a way around is being able to return a char rather than having to
wrap them as Characters. I suppose you could create a CharacterHolder that
isn't immutable and return the same instance with different contents each
time, but that seems cheesy.
.
- References:
- Exception Names
- From: Roedy Green
- Re: Exception Names
- From: Tom Anderson
- Re: Exception Names
- From: rossum
- Re: Exception Names
- From: Lew
- Re: Exception Names
- From: Mike Schilling
- Re: Exception Names
- From: Owen Jacobson
- Exception Names
- Prev by Date: Re: Implementing caches that may be cleared if heap space shrinks away
- Next by Date: Re: Exception Names
- Previous by thread: Re: Exception Names
- Next by thread: Re: Exception Names
- Index(es):