Re: [AD] 4.3 error handling |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Wednesday 07 June 2006 19:36, Jon Rafkind wrote:
> As an alternative what
> about adding the return code to an accumulator and checking if that is
> non-zero at the end of some block of code. If its non-zero, an error
> occurred.
That's even uglier. And you're not acocunting the create functions (which will
return NULL on failure or a valid object on success). The idea is to let the
user deal with the errors if they want, or to let them whip code together
quickly that'll properly abort with a useful message when there's a problem
(and since abort raises a SIGABRT, a debugger can properly catch it and
backtrace uncaught errors, not catch a SIGSEGV several lines later that may
be no where near the source of the error).
> This would only work if subsequent lines of code wouldnt crash
> the program if the previous lines failed for whatever reason.
That's it, too. Just about everything in that code snippet would prevent the
rest of the code in the try block from working. You'd have to resort to
checking each and every function, still.