[Qt-interest] Exceptions caught in queued connections
Gilles Valette
gilles.valette at univ-reims.fr
Fri Dec 11 07:08:07 CET 2009
Message de Santhosh Y <santhosh at softjin.com>:
> Hi,
>
> Following is the message that Qt dumps when I am trying to catch the
> exception in a SLOT (queued connection).
> -------------------------------------------------------------------------
> 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.
> -------------------------------------------------------------------------
>
> The following link exactly points to the problem I am facing now.
> http://lists.trolltech.com/qt-interest/2008-05/thread00942-0.html[1]
>
> The solution suggested is that, we need to reimplement
> bool QCoreApplication::notify ( QObject[2] * /receiver/, QEvent[3] *
> /event/ ) [virtual]
>
> can anybody suggest me how to override the above function,
> so that my exceptions are handled in this function.
>
> I did not find event type as an Exception type so that I can handle
> or return from there!
>
Hi,
Here is an example of what you can do:
class MyApp : public QCoreApplication
{
public:
MyApp(int &argc, char **argv) : QCoreApplication(argc,argv) {}
bool notify( QObject * receiver, QEvent * event )
{
// try block
try {
// call to the ancestor's method
return QCoreApplication::notify(receiver,event);
}
// if an exception is launched
catch( myException &e ) {
qDebug() << "Exception: " << e.what();
return true;
}
catch( ... ) {
qDebug() << "Unknown exception. Exit.";
exit(1);
//return true;
}
}
};
Hope this helps,
Gilles
More information about the Qt-interest-old
mailing list