catch exceptions which leak outside of event handlers
authorkirilma <kirilma@localhost>
Mon, 12 Apr 2010 06:43:53 +0000 (06:43 +0000)
committerkirilma <kirilma@localhost>
Mon, 12 Apr 2010 06:43:53 +0000 (06:43 +0000)
If we do not do this, QT will exit from event loop.

src/app/app.pro
src/app/application.cpp [new file with mode: 0644]
src/app/application.h [new file with mode: 0644]
src/app/main.cpp

index 7d2d4791844dd9d320d20170a668137a33926f33..64d608c94f4f29f0c2cffb6929c463ca2d935394 100644 (file)
@@ -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 (file)
index 0000000..353d8c7
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+#include "application.h"
+
+#include <ormrecord.h>
+
+// 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 (file)
index 0000000..8679b41
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+#ifndef APPLICATION_H
+#define APPLICATION_H
+
+#include <QApplication>
+
+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
index 777a0fc9583a9cea443346be7c7d21ea868452ea..6a32ae9e8dfbe385abe3b9c6ddbc3998d8f481eb 100644 (file)
  */
 #include <mainwindow.h>
 
-#include <QtGui/QApplication>
 #include <sqlengine.h>
 
 #include "eventdialog.h"
+#include "application.h"
 
 #ifdef MAEMO
 //#include <alarmdialog.h>
@@ -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