Re: Error handling

From: Barry Schwarz (schwarzb_at_deloz.net)
Date: 04/23/04

  • Next message: Joe Wright: "Re: Opinion) Overuse of symbolic constants"
    Date: 23 Apr 2004 00:47:29 GMT
    
    

    On Thu, 22 Apr 2004 17:32:33 +0200, Alberto Giménez
    <algibe@teleline.es> wrote:

    >-----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,

    Which ones do you think use -1 to indicate errors. I know some that
    use NULL, some that use EOF, at least one that uses 1, and a few that
    use 0, and at least one where -1 is a normal return value. But off
    the top of my head I cannot think of one that uses -1.

    >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).

    Instructor preferences vary but when I was teaching I always gave
    preference to user friendliness. Will including a function name in an
    error message be meaningful to your user?

    >
    >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?

    For those functions which return an error indication, the standard
    specifies what that indication is on a function by function basis.
    The standard does not specify what your program should do when such a
    condition is indicated.
    >
    >TIA

    <<Remove the del for email>>


  • Next message: Joe Wright: "Re: Opinion) Overuse of symbolic constants"

    Relevant Pages

    • Re: non blocking sockets
      ... process or thread is one that is "waiting for some condition (other than the ... This can certainly include a page fault. ... > want to say blocking is or isn't, the standard says it won't. ... >> means the condition it indicates was true at the time the indication ...
      (comp.unix.programmer)
    • Re: non blocking sockets
      ... It means that at some point your oil was low. ... > indication is latched for you, ... What the standard says is that it will not ... caller yet. ...
      (comp.unix.programmer)
    • Re: Error Raising and Memory in VB (general question)
      ... what is your standard to hanlde errors? ... memory releasing, recordset closing etc.. ... Windows-API style of error handling. ... MsgBoxLog is a more interesting thing, it is declared almost exactly as the ...
      (microsoft.public.vb.general.discussion)
    • Re: Error.pm and try/catch/throw
      ... fishfry wrote: ... > Is Error.pm the standard way to do error handling these days? ... It seems to me that the try/catch/throw method is an ...
      (comp.lang.perl.misc)
    • Re: reading from multiple ports
      ... > DS> can't rely upon 'select's indication that an operation wouldn't ... > Why I can't rely operation wouldn't blocked, if socket is marked ... Actually the standard says that it won't block. ... "A descriptor shall be considered ready for reading when a call to ...
      (comp.unix.programmer)