Xref: utzoo comp.software-eng:4431 comp.lang.c:33730 Path: utzoo!attcan!uunet!crdgw1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!sol.usc.edu!siemsen From: siemsen@sol.usc.edu (Pete Siemsen) Newsgroups: comp.software-eng,comp.lang.c Subject: Re: error handling techniques? Message-ID: <28078@usc> Date: 12 Nov 90 22:27:18 GMT References: <1990Nov2.205831.23696@elroy.jpl.nasa.gov> <1990Nov3.153643.26368@clear.com> <286@dcsun21.dataco.UUCP> Sender: news@usc Followup-To: comp.software-eng Lines: 35 Nntp-Posting-Host: sol.usc.edu amodeo@dataco.UUCP (Roy Amodeo) writes: >One solution to this is to use a stack of errnos and errparms instead of >single global variables. It also helps to have a user definable error >string that is saved in this stack. As the error gets passed up the call >chain more information is added. If the main program chooses to abort, >the entire error stack can be dumped giving a complete description of the >error. Although this generates really nicely detailed error messages >with very little coding trouble, I have not used it on any programs that >have enough levels of function calling to make it really worthwhile. I used exactly such a scheme on a project a few years ago. It worked very well, but meant that every subroutine call (this was FORTRAN) took about 6 lines of code. At any level, a subroutine could decide to "handle" errors from below, or pass the errors on up (adding it's own idea of what was wrong first). Once we got used to the verbosity (in C, macros would reduce this), we were impressed with how well it worked. Whenever an error occurred, you'd get a message something like GETREC: READ failed: illegal logical unit number READFILE: unable to read record from file COPYFILES: unable to read input file ABC.DEF MAIN: unable to copy files which is about as helpful as it gets. This was one of the smoothest software projects I have ever worked on. Of course, there were only five of us working on the code (for about 9 months), and we all agreed on the error system before starting. The customer was very pleased. -- Pete Siemsen Pete Siemsen siemsen@usc.edu University of Southern California 645 Ohio Ave. #302 (213) 740-7391 (w) 1020 West Jefferson Blvd. Long Beach, CA 90814 (213) 433-3059 (h) Los Angeles, CA 90089-0251