Re: Exception Names
On Wed, 01 Apr 2009 00:12:06 +0100, Tom Anderson wrote:
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.
The PL/1 subset G version was even uglier:
dcl file_end bit(1) init('0'B);
on endfile(filename) file_end = '1'B;
do until(file_end);
read file(filename) into(file_rec);
call process_record(file_rec);
end;
....but then I remember somebody saying that PL/1 was designed by taking
the more awkward features of COBOL and Fortran, wrapping them in a block
structure and adding any additional misfeatures that seemed like a good
idea at the time. IMO it makes even COBOL look well designed.
The exception trap (the ON statement) really stands out as a misfeature
because it can be put anywhere in the program provided its outside the
block that contains its trigger and, as you can see, has no direct
connection with the control structure it affects.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |