gdb not catching std::out_of_range thrown by vector

c++, gdb, mingw

Solution

As you've seeen, the exception from `std::vector::at()` is thrown by `__throw_out_of_range` which is a function inside `libstdc++.so`, so I suspect there's some problem on Mingw that prevents GDB from setting a catchpoint in a shared library. Or maybe your `libstdc++` wasn't built with `-g`.

If your GCC was configured with `--enable-libstdcxx-debug` you would have a second set of libs built with `-O0 -g` that might work better when debugging, but that option isn't used often.

Problem

Compiling the following with MinGW 4.6.2 (with g++ -g -std=c++0x), gdb doesn't seem to want catch the `std::out_of_range` if I try `catch throw`. if I `throw` it manually it catches fine, am I doing something wrong? ``` #include <stdexcept> #include <vector> int main() { std::vector<char> vec(10); try { vec.at(10); // this won't be caught by gdb // throw std::out_of_range(""); // this will } catch (std::out_of_range const& e) { } } ```

Original source