[e-lang] Remaining semantic issues
Bill Frantz
frantz at pwpconsult.com
Fri Jun 10 23:51:29 EDT 2005
On 5/31/05, markm at cs.jhu.edu (Mark Miller) wrote:
>I think this is a terribly important question. My general experience is that
>API designers go to a lot of trouble to distinguish different error cases, so
>callers could dispatch on them, but that callers invariably do something like
>
> if (read(...) < 0) {
> perror(...)
> // react to a failure to read
> }
>
>Could you show us some code that dispatches on these errors to do something
>useful? A few illustrative examples of successful error handling, which depend
>on what error happened, may teach us all a lot.
The case I have used the most often involves end of file (EOF) detection. How this appears to the programmer is quite language and library dependant, for example:
* PL/I uses the ON ENDFILE construct, which is like catching an exception. It is separate from the method used to report I/O errors.
* C returns a negative value, and you must consult errno to determine if it is EOF or some other condition.
* Java throws EOFException, a subclass of IOException. Note that treating EOF and I/O errors as the same animal is almost always wrong for production quality code.
Cheers - Bill
---------------------------------------------------------------------
Bill Frantz | The first thing you need | Periwinkle
(408)356-8506 | when using a perimeter | 16345 Englewood Ave
www.pwpconsult.com | defense is a perimeter. | Los Gatos, CA 95032
More information about the e-lang
mailing list