From 77e06ae82216f3f37061e84abe4a529b5179bc04 Mon Sep 17 00:00:00 2001 From: kirilma Date: Mon, 12 Apr 2010 06:43:53 +0000 Subject: [PATCH] catch exceptions which leak outside of event handlers If we do not do this, QT will exit from event loop. --- src/app/app.pro | 2 ++ src/app/application.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/app/application.h | 37 +++++++++++++++++++++++++++++++++++++ src/app/main.cpp | 6 +++--- 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 src/app/application.cpp create mode 100644 src/app/application.h diff --git a/src/app/app.pro b/src/app/app.pro index 7d2d479..64d608c 100644 --- a/src/app/app.pro +++ b/src/app/app.pro @@ -17,10 +17,12 @@ maemo { } HEADERS += appsettings.h \ + application.h \ alarmdbus.h \ alarmdbusadaptorp.h SOURCES += main.cpp \ + application.cpp \ appsettings.cpp \ alarmdbus.cpp \ alarmdbusadaptor.cpp diff --git a/src/app/application.cpp b/src/app/application.cpp new file mode 100644 index 0000000..353d8c7 --- /dev/null +++ b/src/app/application.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2010 Ixonos Plc. + * + * This file is part of fosdem-schedule. + * + * fosdem-schedule is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 2 of the License, or (at your option) + * any later version. + * + * fosdem-schedule is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * fosdem-schedule. If not, see . + */ +#include "application.h" + +#include + +// if the application uses exceptions, +// there is always a possibility that some will leak uncached from event handler +// crashing the application is too big punishment for it +bool Application::notify(QObject* receiver, QEvent* event) +{ + try { + return QApplication::notify(receiver, event); + } catch (OrmException& e) { + qWarning() << "UNCAUGHT EXCEPTION: OrmException, text= " << e.text(); + return false; + } catch (...) { + qWarning() << "UNCAUGHT EXCEPTION: unknown"; + return false; + } +} diff --git a/src/app/application.h b/src/app/application.h new file mode 100644 index 0000000..8679b41 --- /dev/null +++ b/src/app/application.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2010 Ixonos Plc. + * + * This file is part of fosdem-schedule. + * + * fosdem-schedule is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 2 of the License, or (at your option) + * any later version. + * + * fosdem-schedule is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * fosdem-schedule. If not, see . + */ +#ifndef APPLICATION_H +#define APPLICATION_H + +#include + +class Application : public QApplication +{ + Q_OBJECT + +public: + Application(int& argc, char** argv) + : QApplication(argc, argv) + { } + virtual ~Application() { } + + virtual bool notify(QObject* receiver, QEvent* event); +}; + +#endif diff --git a/src/app/main.cpp b/src/app/main.cpp index 777a0fc..6a32ae9 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -18,10 +18,10 @@ */ #include -#include #include #include "eventdialog.h" +#include "application.h" #ifdef MAEMO //#include @@ -36,8 +36,8 @@ int main(int argc, char *argv[]) Q_INIT_RESOURCE(maps); Q_INIT_RESOURCE(db); - QApplication a(argc, argv); - QApplication::setWindowIcon(QIcon(":/icons/fosdem.png")); + Application a(argc, argv); + Application::setWindowIcon(QIcon(":/icons/fosdem.png")); SqlEngine::initialize(); // creates "SQLITE" DB connection -- 2.39.5