-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi there! I'm doing some homework (almost finished), but now i'm
reconsidering a design decission I made at the beginning. This is about
error handling in functions. I have my functions returning 0 if OK, and
an "enum" error indicating the type of error. A typical pseudo-code is
like:
if (error1)
return E_NOMEM;
....
if (error2)
return E_CLOSED;
....
Then, I have some modules calling functions of some others, so I have up
to 3-deep "own function calling". Each of this "deep level" returns 2 or
3 kinds of error (E_FOO, E_BAR,...), and I considered to bypass all
error to topmost calling function or even main program, but the
problem is that in the main program i should have a code like:
status = myfunc ();
switch (status) {
case 0: /* ok */
...
case E_NOMEM:
...
case E_CLOSED:
...
}
and something like this for all my functions returning more than one
value indicating a diferent error. This way my program can indicate
more or less exactly what produced an error in the execution.
I've seen that standard C functions use -1 for error, modifying errno,
but I don't like this handling, because i would have personal error
types. In the other hand, my error handling and bypassing is not very
good (I think).
Now I'm considering to just return -1 (or another nonzero value) in all
functions if there is any error, and the top caller just would indicate
something like "there was an error in myfunc ()" (with no clue if there
was a sub-call error inside myfunc).
I'm doing error-bypassing to the caller because I want my code
modular, and don't want IO functions messing around inside my
modules (a kind of OOP). For this reason, only the main program should
write messages to the user.
In the other hand, does C standard say anything about error handling in
functions?
TIA
- --
Alberto Giménez, SimManiac en el IRC
http://www.almorranasozial.es.vg
GNU/Linux Debian Woody 3.0 GnuPG ID: 0x3BAABDE1
Linux registered user #290801
Iniciando Windows 98... 2 horas despues.... Iniciando Windows 98...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQFAh+WR0keCtzuqveERAlP+AJ9IN+qpwkTJ0TQ3rv2BlQ wEB3DESgCeIzjD
SrcKrjKmKCcAjij0SkECogc=
=PIEb
-----END PGP SIGNATURE-----