[QGIS Commit] r9319 - trunk/qgis/src/core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Sep 13 13:42:22 EDT 2008
Author: telwertowski
Date: 2008-09-13 13:42:22 -0400 (Sat, 13 Sep 2008)
New Revision: 9319
Modified:
trunk/qgis/src/core/qgsapplication.cpp
trunk/qgis/src/core/qgsapplication.h
Log:
Add exception handler for all events. This will catch uncaught exceptions thrown by event handlers and display an alert instead of crashing. Improvement, not fix, for #1308 and #1268.
Modified: trunk/qgis/src/core/qgsapplication.cpp
===================================================================
--- trunk/qgis/src/core/qgsapplication.cpp 2008-09-13 15:11:16 UTC (rev 9318)
+++ trunk/qgis/src/core/qgsapplication.cpp 2008-09-13 17:42:22 UTC (rev 9319)
@@ -19,12 +19,11 @@
#include "qgsproviderregistry.h"
#include <QDir>
+#include <QMessageBox>
#include <QPalette>
-#include <qgsconfig.h>
+#include "qgsconfig.h"
-#include <iostream>
-
// for htonl
#ifdef WIN32
#include <winsock.h>
@@ -68,6 +67,21 @@
QgsApplication::~QgsApplication()
{}
+bool QgsApplication::notify( QObject * receiver, QEvent * event )
+{
+ // Send event to receiver and catch unhandled exceptions
+ bool done = true;
+ try
+ {
+ done = QApplication::notify( receiver, event );
+ }
+ catch ( std::exception & e )
+ {
+ QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() );
+ }
+ return done;
+}
+
void QgsApplication::setPrefixPath( const QString thePrefixPath, bool useDefaultPaths )
{
mPrefixPath = thePrefixPath;
Modified: trunk/qgis/src/core/qgsapplication.h
===================================================================
--- trunk/qgis/src/core/qgsapplication.h 2008-09-13 15:11:16 UTC (rev 9318)
+++ trunk/qgis/src/core/qgsapplication.h 2008-09-13 17:42:22 UTC (rev 9319)
@@ -28,6 +28,9 @@
QgsApplication( int & argc, char ** argv, bool GUIenabled );
virtual ~QgsApplication();
+ //! Catch exceptions when sending event to receiver.
+ virtual bool notify( QObject * receiver, QEvent * event );
+
/** Set the active theme to the specified theme.
* The theme name should be a single word e.g. 'default','classic'.
* The theme search path usually will be pkgDataPath + "/themes/" + themName + "/"
More information about the QGIS-commit
mailing list