In comp.lang.c, pereges wrote:
> Hi, I'm thinking of having a seperate module in my project that deals
> with the exceptions and errors as they occur in a C program. Is this a
> good idea ?
IMHO, for a small number of common exceptions and/or errors, this is a good
idea, but it breaks down when you want to generalize it, or later add
behaviour changes.
[snip]
> This situation may arise in many places in different contexts so what
> I would like to do is identify such cases and have a seperate module
> with a switch case that takes an error flag as an input and makes the
> decision based on it.
For a limited number of errors or exception conditions, this would work.
But, it isn't scalable, and your initial design/implementation may not
properly handle exceptional processing.
For example, your initial design may simply report the error and call
exit(). Subsequently, you may find reason to report the error and return
back to the caller, or report the error and request a user decision, or
silently handle the error and return. Each one of these changes would
necessitate corresponding behavioural changes in your common handler, along
with a (possibly) ever-growing list of function arguments (function,
message, output-log-file FILE, user-input-action-message,
user-input-options, user-input-file FILE, user-input-via-GUI flag,
exit/return code, abnormal-termination-with-core-dump flag, ...).
You need to be careful about how you design the initial function, and under
what circumstances it will be used, otherwise accomodating your "exception
handler" function may consume more programming resources than the rest of
the program.
[snip]
> Is there a function in C which provides this facility ?
Not in ISO standard C, no.
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------