src/hbservers/hbdevicedialogappserver/main.cpp
changeset 30 80e4d18b72f5
parent 28 b7da29130b0e
--- a/src/hbservers/hbdevicedialogappserver/main.cpp	Fri Sep 17 08:32:10 2010 +0300
+++ b/src/hbservers/hbdevicedialogappserver/main.cpp	Mon Oct 04 00:38:12 2010 +0300
@@ -32,6 +32,8 @@
 #include <hbtransparentwindow.h>
 #include <hbstackedlayout.h>
 #if defined (Q_OS_SYMBIAN)
+#include <QFile>
+#include <QDir>
 #include <aknappui.h>
 #include <eikenv.h>
 #include <apgwgnam.h>
@@ -186,7 +188,34 @@
     RProcess::Rendezvous(KErrNone);
 #endif // Q_OS_SYMBIAN
 
-    int returnValue = app.exec();
+    // Unhandled exceptions mostly do not end up here. Instead they
+    // go to Symbian exception handler which crashes the server.
+    int returnValue = 0;
+    bool hadException = true;
+    try {
+        returnValue = app.exec();
+        hadException = false;
+    } catch (const std::bad_alloc &) {
+        returnValue = 1;
+    } catch (...) {
+        returnValue = 2;
+    }
+
+    TRACE_EXIT_ARGS("excep =" << hadException << "ret =" << returnValue);
+
+#if defined (Q_OS_SYMBIAN)
+    // Server exit is abnormal. Log event of it.
+    QString logPath("c:/logs");
+    QDir logDir;
+    if (!logDir.exists(logPath)) {
+        logDir.mkpath(logPath);
+    }
+    QFile logFile(logPath + "/hbdevdlgsrv.txt");
+    if (logFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
+        logFile.write(QString().setNum(returnValue).insert(0, hadException ? 'E':'R').toAscii());
+        logFile.close();
+    }
+#endif // Q_OS_SYMBIAN
 
     UNINSTALL_MESSAGE_HANDLER