Skip to content

Commit

Permalink
Add exception handler for all events. This will catch uncaught except…
Browse files Browse the repository at this point in the history
…ions thrown by event handlers and display an alert instead of crashing. Improvement, not fix, for #1308 and #1268.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9319 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
telwertowski committed Sep 13, 2008
1 parent f535673 commit 34111be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/core/qgsapplication.cpp
Expand Up @@ -19,11 +19,10 @@
#include "qgsproviderregistry.h"

#include <QDir>
#include <QMessageBox>
#include <QPalette>

#include <qgsconfig.h>

#include <iostream>
#include "qgsconfig.h"

// for htonl
#ifdef WIN32
Expand Down Expand Up @@ -68,6 +67,21 @@ QgsApplication::QgsApplication( int & argc, char ** argv, bool GUIenabled )
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;
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsapplication.h
Expand Up @@ -28,6 +28,9 @@ class CORE_EXPORT QgsApplication: public QApplication
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 + "/"
Expand Down

0 comments on commit 34111be

Please sign in to comment.