Discussion:
Slot exception being thrown on exit
(too old to reply)
Ramakanth Kesireddy
2018-03-06 17:30:21 UTC
Permalink
Raw Message
Hi,

When Qt application is being exited, it throws below error:-

Qt has caught an exception thrown from an event handler. Throwing
exceptions from an event handler is not supported in Qt. You must
reimplement QApplication::notify() and catch all exceptions there.

Please let me know if there is any way to find out the slot or eventhandler
throwing exception
other than running the app in debug mode with backtrace?

Thanks and Regards,
RK
Jason H
2018-03-06 17:47:37 UTC
Permalink
Raw Message
_______________________________________________
Interest mailing list
***@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
Thiago Macieira
2018-03-06 17:59:49 UTC
Permalink
Raw Message
Post by Ramakanth Kesireddy
Please let me know if there is any way to find out the slot or eventhandler
throwing exception
other than running the app in debug mode with backtrace?
Run in the debugger and ask it to stop in any C++ exception thrown (gdb
command "catch throw").
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
Ramakanth Kesireddy
2018-03-14 02:08:00 UTC
Permalink
Raw Message
Hi,

Thanks a lot for the pointers and tried both approaches but couldnot trace
the slot where exception is being thrown.
I re-implemented notify but the exception is not being caught.

class Application: public QApplication {

public:
Application(int& argc, char** argv,int = ApplicationFlags):
QApplication(argc, argv,ApplicationFlags)
{
qDebug() << "Application constructor: " << endl;
}

virtual bool notify(QObject* receiver, QEvent* event) {
try {
qDebug() << "Application notify: " << endl;
return QApplication::notify(receiver, event);
}
catch (const std::exception& exc) {
qDebug() << "Application caught exc: " << exc.what() << endl;
return true;
}
catch(...) {
qDebug() << "Application caught undefined exception" << endl;
return true;
}
}
};

new Application ( argc
, argv
, Application::GuiServer );

Only difference being Qt app is spawned as the child thread of other
process.
Even if I commented all the connect statements, the below exception is
being thrown:-

Qt has caught an exception thrown from an event handler. Throwing
exceptions from an event handler is not supported in Qt. You must
reimplement QApplication::notify() and catch all exceptions there.

Though it works as expected in a sample app, still unable to find the
rootcause.
Please suggest in this regard.

Thanks and Regards,
RK
Post by Ramakanth Kesireddy
Post by Ramakanth Kesireddy
Please let me know if there is any way to find out the slot or
eventhandler
Post by Ramakanth Kesireddy
throwing exception
other than running the app in debug mode with backtrace?
Run in the debugger and ask it to stop in any C++ exception thrown (gdb
command "catch throw").
--
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
Thiago Macieira
2018-03-14 04:04:03 UTC
Permalink
Raw Message
Post by Ramakanth Kesireddy
new Application ( argc
, argv
, Application::GuiServer );
There are two problems in the above line. Not fatal, but they are worrisome.

First, "new Application" is probably wrong. Create it on the stack. If your
application has a problem with that, then redesign so that the problem goes
away. The class deriving from QCoreApplication is supposed to be created in
main(), be the first QObject created and the last destroyed. If you're using
new, you're probably trying to make it outlive the function it's created in,
which is weird.

Second, what is that third parameter? QApplication has a hidden third
parameter which is a failed attempt at determining the Qt version to be
compatible with. But you should not be passing anything to it. Your
Application class doesn't use the parameter it receives either.
Post by Ramakanth Kesireddy
Qt has caught an exception thrown from an event handler. Throwing
exceptions from an event handler is not supported in Qt. You must
reimplement QApplication::notify() and catch all exceptions there.
Though it works as expected in a sample app, still unable to find the
rootcause.
Please suggest in this regard.
Put a breakpoint in the throw function. If you're using GCC or Clang, it's
__cxa_throw.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
Loading...