------- Forwarded message -------
From: Voguemaster <[EMAIL PROTECTED]>
To: guy keren <[EMAIL PROTECTED]>
Subject: Re: OT: PROG question: regarding returning errors in libraries
Date: Fri, 07 Feb 2003 15:52:36 +0200

Well, I can only speak from my exprience. When I wrote a mail relay
server, I've used a model where each module defines it's functions
and the error codes they can generate. For example, the module that
handles all TCP related issues contain several wrapper functions
and these functions are returning predefined error codes to the calling
function. This is part 1 of the error reporting scheme. Part 2 is all
about logging errors but i'll get there soon enough.
As for the caller, I've implemented a way to take the error code and
generate a specific string from it, much like perror does for standard
library errors. In addition I've included the optional user string to
be added, along with another string that is automatically pre-added that
actually represents the function name. The function names are also predefined
in my header files and there is a lookup function that returns the function
name per ID that you pass to it.
Using this I could also write a nice logging mechanism that tells when
an error occured (say, a broken pipe when sending data to the TCP socket)
or some other condition occured and sends the info either to syslog or
to some specific log files.

So to sum up, the method I've used is predefined function error codes
per function, per module. In addition, function IDs that can be added
to the error string that can be generated with a function that behaves
much like perror (or GetLastError if you'd like).

Thinking back, I might've used a scheme more closely related to exception
handling, but for plain C.

The only annoying thing with my scheme is that there are literally LOTS
of error IDs and you have to be very careful when you assign new ones.
You don't want collisions naturally. Also, adding a bunch of functions
to a library is also annoying since you need new IDs and add the necessary
names to your lookup function etc..

Eli

i wonder what people here have to add regarding these models, or regarding other models (again - for the "C" language) they have used, or wanted to try to use.

if you comment - please state if you're talking about somehting you used, something you've started using lately, or something you didn't yet use. or if its soemthing you've read about somewhere. and please be fair - i.e. when you describe your magnificent no-problem error reporting system, please also state what are the bad parts of it - where it was annoying, what in it would you improve if you had the time, or if you had an idea how to do, etc.

thanks,




--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to