Darren New wrote:
Christopher Smith wrote:
It's not the *throwing* exceptions inside a destructor that is a problem. You can and should do that as appropriate. You just can't let exceptions bubble past the destructor.
Let me paraphrase to make sure I have it right:

In other words, you can't let the destructor actually throw an exception. If some statement inside the destructor throws an exception, you have to catch it inside the destructor.
I think you have the concept. Technically you can let exceptions out from the destructor, just not if you're already in the process of unwinding the stack.
I would find that inconvenient. I simply log *all* exceptions, catching *everything* at the top level that I don't expect to fix lower down.
Oh it can be. That's why people bitch about it as the issue with C++'s exceptions.

That said, the right place to log an exception is not way at the top level. 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. Usually you want to log it around the area where you throw it.

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. So, the real pain only shows up for the cases where there is something you might be able to do with it *outside* of the immediate context of the destructor. Those situations turn out to be fairly rare, and there are various ways of hacking around the problem, but it is a PITA when it comes up.

--Chris

--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to