help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Exceptions failing in libstdc++


From: Larry I Smith
Subject: Re: Exceptions failing in libstdc++
Date: Mon, 21 Mar 2005 20:39:05 GMT
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041220

Larry I Smith wrote:
red floyd wrote:

G++ 3.2.3 (RedHat Enterprise Linux 3), x86

g++ --version returns:

g++ (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-49)

Boiled down to essentials (and unfortunately, the minimun example won't barf), I have:


class X {
public:
  X() { /* ... */ };
  // ... etc etc...
};


void f()
{
    throw X();
}

void g()
{
 // yada yada yada
  try {
    f();
  }
  catch (X&)
  {
    // do something
  }

}


But when f() throws X as an exception, the program terminates,
and the libstdc++ code in __cxa_throw has a comment of:

    // Some sort of unwinding error.  Note that terminate is a handler.
    __cxa_begin_catch (&header->unwindHeader);
    std::terminate ();

The full-bore code in question works properly under VC7.1

GDB shows that the call to f() is occuring within a try/catch block, which catches X&.

I'm compiling with -pthread -fexceptions

Any suggestions?



Exceptions work fine in GCC.  Your minimal example verifies
that.

The '-fexceptions' flag is not required.  'g++' always enables
exceptions for C++ source files.  That flag may be of use when
compiling C source files that will be linked with C++ files
(see 'info gcc' for details).

You've probably uncovered a flaw in your program (stack being
overwritten, flaw in X() constructor, etc, etc) that is causing
the exception handling info on the stack to become corrupted.

Things are laid out differently in memory (gcc vs msvc); even
struct sizes and layouts may differ.

Regards,
Larry


Correct me if I'm wrong (it's been awhile)...

If an exception is thrown in a thread, only that thread can
catch it (because each thread has its own stack)?  If that
is the case, then the try/catch(&X) block must be in the
same thread (and in an ancestor method of the method that
throws X) as the 'throw X()' statement.

Regards,
Larry

--
Anti-spam address, change each 'X' to '.' to reply directly.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]