Discussion:
Retrieving the object info due to exception
(too old to reply)
Ramakanth Kesireddy
2018-02-27 17:42:51 UTC
Permalink
Raw Message
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?
alexander golks
2018-02-28 06:47:35 UTC
Permalink
Raw Message
Am Tue, 27 Feb 2018 23:12:51 +0530
Post by Ramakanth Kesireddy
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
*/
Konstantin Tokarev
2018-02-28 23:23:22 UTC
Permalink
Raw Message
Post by alexander golks
Am Tue, 27 Feb 2018 23:12:51 +0530
 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?
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.
Or don't get any bad_alloc at all, being killed by OOM Killer promptly
Post by alexander golks
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
 */
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
--
Regards,
Konstantin
Thiago Macieira
2018-02-28 23:51:34 UTC
Permalink
Raw Message
Post by alexander golks
bad_alloc is mostly thrown due to too view memory for the request in question.
Post by alexander golks
so when you continue your program, chances are good to see more bad_allocs.
Or don't get any bad_alloc at all, being killed by OOM Killer promptly
You get bad_alloc when you make silly requests, like negative sizes or
petabytes.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
Ramakanth Kesireddy
2018-03-01 17:34:42 UTC
Permalink
Raw Message
When system runs on low memory, the object allocations through new in the
Qt application does throw bad_alloc exception,right?
Post by Thiago Macieira
Post by alexander golks
bad_alloc is mostly thrown due to too view memory for the request in question.
Post by alexander golks
so when you continue your program, chances are good to see more bad_allocs.
Or don't get any bad_alloc at all, being killed by OOM Killer promptly
You get bad_alloc when you make silly requests, like negative sizes or
petabytes.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Konstantin Tokarev
2018-03-01 17:45:48 UTC
Permalink
Raw Message
When system runs on low memory, the object allocations through new in the Qt application does throw bad_alloc exception,right?
It may or may not throw exception, depending on OS kind, overcommit settings,
memory limits set for your application, and your luck.
Post by Thiago Macieira
Post by alexander golks
bad_alloc is mostly thrown due to too view memory for the request in question.
Post by alexander golks
so when you continue your program, chances are good to see more bad_allocs.
Or don't get any bad_alloc at all, being killed by OOM Killer promptly
You get bad_alloc when you make silly requests, like negative sizes or
petabytes.
--
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
,
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
-- 
Regards,
Konstantin
Ramakanth Kesireddy
2018-03-02 03:58:10 UTC
Permalink
Raw Message
Thanks all for your thoughts.
Assuming that it throws bad_alloc exception, I added global replacement of
new operator but it throws linker error of multiple definition of new
operator though it seems to invoke overloaded version of new operator with
filename and line no.Any pointers on how to avoid ld error?
Post by Konstantin Tokarev
Post by Ramakanth Kesireddy
When system runs on low memory, the object allocations through new in
the Qt application does throw bad_alloc exception,right?
Post by Konstantin Tokarev
It may or may not throw exception, depending on OS kind, overcommit settings,
memory limits set for your application, and your luck.
Post by Ramakanth Kesireddy
Post by Thiago Macieira
Post by alexander golks
bad_alloc is mostly thrown due to too view memory for the request in question.
Post by alexander golks
so when you continue your program, chances are good to see more bad_allocs.
Or don't get any bad_alloc at all, being killed by OOM Killer promptly
You get bad_alloc when you make silly requests, like negative sizes or
petabytes.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
,
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
--
Regards,
Konstantin
Thiago Macieira
2018-02-28 17:03:27 UTC
Permalink
Raw Message
Post by Ramakanth Kesireddy
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?
There isn't, not portably.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
Loading...