PDA

View Full Version : Crash gracefully? No crash!



lni
7th July 2010, 04:59
We have a library that works for both Linux and Windows to catch all kinds of crashes: segmentation fault, double free, referencing invalid memory, division by zero, etc. This is the interface:



class QFW_QfwException_EXPORT QfwApplication : public QApplication
{
Q_OBJECT;

public:

QfwApplication( int& argc, char** argv );
~QfwApplication();

// re-implement base method
virtual bool notify ( QObject * receiver, QEvent * event );

protected:

// call right after exceptionOccurred signal is emitted
virtual void processException( const QString& errMsg );

signals:

// signal emitted when an exception occurred
void exceptionOccurred();

private:

class QfwApplicationPrivate;
QfwApplicationPrivate* _privateData;

};



We test using the following code and program does not crash.



void Ui_Form::testSingleThread()
{
qDebug() << "Ui_Form::testSingleThread";
float* x = 0;
x[ 0 ] = 0;
}


All you need to do is to replace your normal Qt's QApplication with QfwApplication for catching those exceptions. The default implementation when such exception occurs will call QMessageBox::critical(...) inside QfwApplication::processException (see attachment), but you can re-implement it. It also emits "exceptionOccurred signal (see QfwApplication interface).

With that, the program returns to normal event loop and never crashes...although it recommends to save the data and restart the program...

This library works for both Linux and Windows (we have not tested other platforms), but is not free.

If interested, please contact me at geomarktech@gmail.com for more info.