dalka (10/26/82)
I always check all error returns on reads/writes/seeks. I do this by: if (fread(&stuff, num, size, fd) != num) ERROR (FATAL, "error, message", interesting_object) where ERROR is: #define WARNING 0 /* warning */ #define ERR 1 /* continue processing, log the error */ #define FATAL 2 /* fatal user error, exit immediately */ #define INTERNAL 3 /* internal tool error, exit immediately*/ /* * define the ERROR macro which will pass line number and source * filename to error subroutine */ #define ERROR(a,b,c) error(__FILE__,__LINE__,(a),(b),(c)) the error message may contain printf formatting macros and the interesting object may either be zero or use the format in the string. The sourcefile name and line number are invaluable when debugging and are sometines turned on or off by setting debugging variables. The error routine can also be made smart enough to know about any temp files open, closing and/or removing them if necessary.
paulson (10/26/82)
Note that exception handling in C can be implemented using setjmp/longjmp library calls, without adding anything to the language. Exception handling of the form used in PL/1, "on any divide by zero do the following", seems to me to be a particularly insidious attack on structured programming. I get a very unsettling feeling when I know that control is being transferred in a program without any explicit statement from the programmer. Bill Paulson ihuxt!paulson
pfc (10/26/82)
#R:ihuxt:-10300:whuxlb:9400004:000:215 whuxlb!pfc Oct 26 13:06:00 1982 PLEASE! No setjmp/longjmp's. I find it amazing that people who advocate getting rid of every single last goto will gladly put in a longjmp. The last is not meant as an ad hominiem (sp?), only a general comment.
jcwinterton (11/01/82)
Somewhat like Bill Paulson, I don't think the idea of PL/1 type ON units are a particularly good idea. However, it does provide neat error trapping if handled correctly and a reasonable repair and return or give up and quit neatly mechanism is available. As for that unsettled feeling, how would one handle a piece of hardware that operates in this way? At least one cpu I know of does exactly, by hardware, what the ON unit idea does. That is, on the interrupt or fault it lays down a new stack frame and transfers to the appropriate handler through a linkage vector. Much hardware does this, in fact, so that some similar mechanism should really exist in a language that purports to be for system programming (operating system that is) purposes. Sigh. It appears that one is d..ned if one does and d..ned if one doesn't. John Winterton.