Re: Why leave the error handling to the caller?



Malcolm McLean said:


"Richard Heathfield" <rjh@xxxxxxxxxxxxxxx> wrote in message
news:7oCdnWXORp3b-ujbnZ2dnUVZ8szinZ2d@xxxxxxxxx
Malcolm McLean said:

<snip>

There quite a strong case for a safemalloc() library function that
does terminate with an error message on fail.

No, there isn't. Library routines have no business deciding to
terminate the program.

The problem is that the code is disproprtionate.

If you try hard enough, the code /can/ be disproportionate.

Let's say I want to set up a structure with a list of strings.

I looked at your code, and found it lacking in any significant evidence
that you are a regular clc subscriber.

<snip>

Now that is about as simple as an arbitrary dataset is likely to be -
just an array of strings. I counted 14 lines purely to handle malloc()
failures.

Get back to me when you've written it properly.

The code is untested and there is probably something wrong with it.

You'd be amazed. Still, look on the bright side - it didn't actually
call gets().

To my mind this is a very serious disadvantage of the "caller handles
error" paradigm.

To my mind it was just a bunch of broken code.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
.



Relevant Pages

  • Re: Why leave the error handling to the caller?
    ... does terminate with an error message on fail. ... Library routines have no business deciding to terminate ... That's rubbish because the above situation is on a modern medium to high spec notebook. ... On my previous company notebook which was high spec at the time I would also run out of resources. ...
    (comp.lang.c)
  • Re: xp pro rebbots for no apperant reason
    ... winlogin.exe failed click ok to terminate or cancel to debug ... go to boot seliction screen and selected safe mode with network support as ... rebooted system through reset button this time error message came up as ... Try to get back to the Windows XP Startup Menu ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: contracted exceptions
    ... superior to the existing rule of silently ignoring the exception. ... The simplest would be to terminate the entire program immediately. ... And print an error message on systems where that makes sense. ... Terminate the parent task and that should become equivalent to "exit". ...
    (comp.lang.ada)
  • Re: Why leave the error handling to the caller?
    ... does terminate with an error message on fail. ... Library routines have no business deciding to terminate ... Should fopenhalt the program if unable to open the file? ... Free games and programming goodies. ...
    (comp.lang.c)
  • Re: Form validation help
    ... The onblur event fires, which checks the value in field1, sees it is invalid, so prints an error message and resets the focus to field2. ... In fact, the blur event should be avoided in general for validation purposes as warnings can become, from the user's perspective, harassment. ...
    (comp.lang.javascript)