Re: Hang in throw
On Sep 21, 11:39 am, Marcel M=FCller <news.5.ma...@spamgourmet.com>
wrote:
jarek wrote:
I have strange problem - program hangs on calling throw. The
program is quite simple, so I don't this that source code
with tell something. The question is: how to debug it? The
same throw called from other places works fine. But from one
hangs program. Debian Lenny, gcc 4.3.2
There is a class:
class Exception : public exception {
[...]
And in some place of code there is:
throw Exception("Command failed!");
In some cases program hangs on this throw statement. What
can be the reason ?
you certainly provided only the unimportant part of the
information. It is essential where you throw an exception!
- You exception could be uncaught. In this case the runtime
will abort your program.
Which isn't the same as hanging.
However, there are places, where this is unwise, because you
are currently executing a callback from the runtime, e.g. a
signal handler.
Throwing an exception from a signal handler isn't allowed, and
may not work. Or it may work most of the time, but not always.
(It's undefined behavior.)
- Your exception could be caught, but that causes a deadlock,
because you threw the exception while holding a mutex. With a
non-recursive mutex this may even happen with a single thread.
- You application code might not be exception safe because of
code fragments with undefined behavior in case of exceptions.
- You may have corrupted the free space arena previously, which
causes the code to hang when constructing the string for the
exception. In fact, any previous undefined behavior can lead to
this sort of problem. But corrupting the free space arena seems
most common.
--
James Kanze