Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!samsung!uunet!lotus!lotus!blambert From: blambert@lotus.lotus.com (Brian Lambert) Newsgroups: comp.lang.c Subject: Managing error strings in C Message-ID: <1991Jan10.122227@lotus.lotus.com> Date: 10 Jan 91 17:22:27 GMT Sender: news@lotus.com Reply-To: blambert@lotus.lotus.com (Brian Lambert) Organization: Lotus Development Corporation Lines: 38 Hi: I was wondering if anyone out there had any clever ways of handling error messages in C. That is, in small/medimum size programs one usually winds up with all sorts of: PrintLog("Memory allocation error"); lines in the program. I have seen code where people define an array of char pointers to error messages used in the program such as: char *errors[] = { "Memory allocation error", "Can't open file", ... }; #define NO_MEMORY 0 #define CANT_OPEN 1 and then prints out the error message by: PrintLog(errors[NO_MEMORY]); I'm sure there are a zillion ways to do this. I have used this method in the past, but was never very happy with it. (It's not very elegant, and is difficult to maintain as one must be sure to use the proper number in the #define.) Got a better idea? Thanks! -- Brian Lambert Lotus Development Corporation blambert@lotus.com