Aurélien Gâteau

Tip of the day: Finding the source of a bad_alloc exception

written on Tuesday, December 22, 2009

Quick tip of the day.

Today I was debugging a bad_alloc exception, but the backtrace was useless because the exception was being rethrown by Qt event loop.

After some head scratching, I figured this simple trick which you may find useful:

b 'std::bad_alloc::bad_alloc()'

This sets a breakpoint on bad_alloc constructor. After restarting the program, I was able to get a much more useful backtrace.

Hope this helps!

This post was tagged bad_alloc, gdb and tips