error checking

utzoo!decvax!harpo!ihps3!ihuxe!dalka utzoo!decvax!harpo!ihps3!ihuxe!dalka
Tue Oct 26 08:48:28 AEST 1982


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.




More information about the Comp.lang.c mailing list