[Interest] Retrieving the object info due to exception std::bad_alloc

alexander golks alex at golks.de
Wed Feb 28 07:47:35 CET 2018


Am Tue, 27 Feb 2018 23:12:51 +0530
schrieb Ramakanth Kesireddy <rama.kesi at gmail.com>:

> Hi,
> 
> As mentioned in http://doc.qt.io/archives/qt-4.8/exceptionsafety.html, the
> below code is being used to catch the exceptions in application:-
> 
> QApplication app(argc, argv);
> ...
> try {
> app.exec();
> } catch (const std::bad_alloc &) {
> //clean up code and log the exception info
> // retrieve class name and method name of object
> return 0; // exit the application
> }
> 
> Please let me know if there any means to get the runtime object info like
> class name, method name(if possible line number) throwing the exception
> std::bad_alloc in catch block?

beside your origin question:
bad_alloc is mostly thrown due to too view memory for the request in question.
so when you continue your program, chances are good to see more bad_allocs.

to your question:
you may try stacktracers, like mentioned here: https://stackoverflow.com/a/691742

alex

-- 
/*
 *No violence, gentlemen -- no violence, I beg of you!  Consider the furniture!
 *    -- Sherlock Holmes
 */



More information about the Interest mailing list