Re: Exception Names



Tom Anderson wrote:
On Tue, 31 Mar 2009, Lew wrote:

Lew wrote:
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.

Tom Anderson wrote:
I'd say that getting end of stream is a highly exceptional event for a read method. The vast majority of the time, you get a byte back!

Nice little bit of rhetorical spin there.

It's not spin, it's a different perspective.

You define majority relative to the number of read events, where I was referring to the number of streams.

Yes, exactly.

I'm going to stand by the notion that most of the time *one uses a stream* one reads the whole thing. Your statement that most of the reads do not hit the end of the stream is trivially correct, but that still doesn't make reading a stream all the way through an exceptional occurrence.

Okay, fair enough.

I also think that whether an event is exceptional has at best a marginal connection to whether it's a good idea to use an exception for it. I think that's an overly literal and dogmatic approach to take.

tom

Generally I see little rhyme or reason as to why some occurrences in Java are handled with return values and others with exceptions. For example, there's nothing exceptional about not finding a file or trying to write to a read-only file, and yet we've got FileNotFoundException.

IOW, exceptions in Java are typically used for _expected_ behaviour. IMHO rather than discussing what exceptions to add, we ought to be discussing how many exceptions that aren't exceptions we can get rid of. An exception should be for a situation that causes a break away from normal program flow...and handling end of stream doesn't fit that bill.

In case I wasn't clear (:-)), I'm arguing for _more_ methods with return values, not less.

AHS
.



Relevant Pages

  • Re: SqlXml MemoryStream Bulk Load Errors
    ... It explains how to create a wrappper Stream that will make Bulkload work ... > CreateStreamOnHGlobal(0, true, out dataStream); ... > //Catch all SQL XML Bulk Load API Exceptions ... > public MemoryStream SqlXmlMemoryStream ...
    (microsoft.public.sqlserver.xml)
  • Re: Exception Names
    ... One would venture to say that one nearly always reaches the end of a stream, ... Generally I see little rhyme or reason as to why some occurrences in Java are handled with return values and others with exceptions. ...
    (comp.lang.java.programmer)
  • Re: Exceptions and Streams
    ... exceptions:: with GNAT, but I'm afraid I can't remember what. ... with 'gnatbind -E', GNAT keeps a traceback in the ... You might find it easier to create a stream which could extend itself ...
    (comp.lang.ada)
  • Re: Exception Names
    ... -1 at the end of a stream. ... It may bee goofy but it is very likely to be a whole lot faster. ... for (char c: stream) ... You have to wrap the exceptions with RuntimeExceptions. ...
    (comp.lang.java.programmer)