[Qt-interest] Handling exceptions in Qt
Sean Harmer
sean.harmer at maps-technology.com
Mon Jul 19 14:12:48 CEST 2010
Hi,
On Monday 19 July 2010 12:58:20 Santhosh Y wrote:
> I read some where to override an API on QApplication / QCoreApplication
> for catching exceptions in a Qt application.
> Can anybody tell me the API which I should override for handling
> exceptions in my app.
You need to override bool QCoreApplication::notify(). For example in one
application we have where a library we are using can throw exceptions we have
this in a class derived from QCoreApplication:
bool ExceptionApplication::notify( QObject* receiver, QEvent* e )
{
try {
return QApplication::notify( receiver, e );
}
catch ( char* err ) {
qDebug() << "ExceptionApplication::notify exception caught:"
<< QString( err );
// Do some other processing here...
}
return false;
}
By catching all your possible exceptions here you prevent the exception
mechanism form unwinding the call stack any further and causing Qt to exit its
event loop.
HTH,
Sean
More information about the Qt-interest-old
mailing list