Customizing uncaught exception messages

Yang Zhang yanghatespam@gmail.com
Thu May 15 15:40:00 GMT 2008


me22 wrote:
> On Thu, May 15, 2008 at 2:03 AM, Yang Zhang <yanghatespam@gmail.com> wrote:
>> Hi, is it possible to get more informative error messages for uncaught
>> exceptions?  For instance, I'm interested in getting Java-like tracebacks
>> with file and line numbers.  Currently what I see is far from that, e.g.:
>>
>> terminate called after throwing an instance of 'std::logic_error'
>>  what():  basic_string::_S_construct NULL not valid
>>
>> Is there any way to hook into the exception handling mechanisms and produce
>> such a traceback?  If the solution is platform-dependent, I am using
>> GNU/Linux with gcc 4.2.3.
>>
> 
> The information isn't stored anywhere, so by the time you get an
> exception falling out of main and calling terminate, it's no longer
> available.
> 
> Your debugger might let you automatically break on throws...

How does gdb manage to hook into the exception-throwing mechanisms to 
trigger breakpoints?  Would I be able to use the same approach to hook 
it up to code that simply stores the backtrace somewhere (perhaps 
thread-local storage), and then hook into the uncaught exception handler 
to print this stored backtrace?

-- 
Yang Zhang
http://www.mit.edu/~y_z/



More information about the Gcc-help mailing list