Christopher Smith wrote:
That said, the right place to log an exception is not way at the top
level.
It depends on what the exception is. Of course, if the exception is
something like "the file I expected didn't open" or "I can't find the
database server", sure you don't throw those. When the exception is
something unplanned for, you really don't know where "close" is.
Indeed, once you get to the top level one is better off, for the
most part, letting the process core dump and spawning a new one.
I find that not to be the case. Of course, my exceptions aren't of the
type "I probably walked all over myself so badly that I have no idea
what's screwed up and couldn't possibly recover", either.
you want to log it around the area where you throw it.
If you know you're going to throw it, sure. A lot of times, the easiest
thing for me to do is assume (for example) that I didn't install the
program correctly, and if a library isn't found, let it throw an error,
log it, retry three times with successively longer pauses, until I
decide it's just not going to work, send a page, *then* exit.
The good news is that exceptional cases tend to be much rarer with
resource release (usually you have problems with resource acquisition
and/or resource use). For example, free(void*) returns void. The other
good news is that generally if you *have* a problem with releasing a
resource, there is precious little you can do about it beyond reporting
the error.
Sure. Maybe I'm just used to languages where throwing an error is the
normal way of reporting an error, rather than (say) returning -1 and
making the caller check. So, for example, things like "close" flushing
the buffer to discover there's no disk space throw an error instead of
silently failing.
I find most people who think exceptions are evil are people who are used
to languages where exceptions are difficult to deal with.
--
Darren New / San Diego, CA, USA (PST)
It's not feature creep if you put it
at the end and adjust the release date.
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg