Boost logo

Boost Users :

From: Bill Lear (rael_at_[hidden])
Date: 2006-05-04 10:33:44

On Wednesday, May 3, 2006 at 09:03:03 (-0700) Robert Ramey writes:
>Heres what I do.
>I run the debugger.
>I set a trap anywhere. or I can wait until it traps on its own.

I did want to share something I kvetched about: the pain in the
neck when C++ exceptions are thrown and you get no call stack of
how that exception came to be thrown (e.g., "stream error").

I discovered what seems to be a fairly easy solution under gdb.

Compile this test code with -g:

    #include <iostream>
    #include <stdexcept>

    using namespace std;

    void a() { throw runtime_error("bad dog"); }
    void b() { a(); }
    void c() { b(); }
    void d() { c(); }

    int main(int ac, char* av[]) {
        try {
        } catch (const exception& e) {
            cerr << "error: " << e.what() << '\n';

In gdb 6.4, you can simply say "catch throw". In the 6.3 version
(perhaps earlier), you can set the "catch throw" after shared
libraries have been loaded:

% gdb ./a.out
(gdb) set stop-on-solib-events 1
(gdb) run
Starting program: /home/blear/a.out
Stopped due to shared library event
(gdb) catch throw
Catchpoint 1 (throw)
(gdb) c
Stopped due to shared library event
(gdb) c
Stopped due to shared library event
(gdb) c

Catchpoint 1 (exception thrown)
0x00aeaf11 in __cxa_throw () from /usr/lib/
(gdb) where
#0 0x00aeaf11 in __cxa_throw () from /usr/lib/
#1 0x08048c04 in a () at
#2 0x08048c0f in b () at
#3 0x08048c1d in c () at
#4 0x08048c2b in d () at
#5 0x08048c50 in main (ac=1, av=0xbff68dd4) at

Hope this helps others.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at