[WIN32] catch exceptions also during Create(), CreateGUI() and Initialize().
authorwsoltys <wiso@no.way>
Fri, 8 Feb 2013 14:42:09 +0000 (15:42 +0100)
committerwsoltys <wiso@no.way>
Sat, 9 Feb 2013 19:29:24 +0000 (20:29 +0100)
xbmc/win32/XBMC_PC.cpp

index 64c6383..06c527c 100644 (file)
 #include "Application.h"
 #include "XbmcContext.h"
 #include "GUIInfoManager.h"
+#include "utils/StringUtils.h"
+
+#ifndef _DEBUG
+#define XBMC_TRACK_EXCEPTIONS
+#endif
 
 // Minidump creation function
 LONG WINAPI CreateMiniDump( EXCEPTION_POINTERS* pEp )
@@ -128,35 +133,86 @@ INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR commandLine, INT )
   // use 1 ms timer precision - like SDL initialization used to do
   timeBeginPeriod(1);
 
-  // Create and run the app
-  if(!g_application.Create())
+#ifdef XBMC_TRACK_EXCEPTIONS
+  try
   {
-    CStdString errorMsg;
-    errorMsg.Format("CApplication::Create() failed - check log file and that it is writable");
-    MessageBox(NULL, errorMsg.c_str(), "XBMC: Error", MB_OK|MB_ICONERROR);
-    return 0;
+#endif
+    // Create and run the app
+    if(!g_application.Create())
+    {
+      MessageBox(NULL, "ERROR: Unable to create application. Exiting.", "XBMC: Error", MB_OK|MB_ICONERROR);
+      return 1;
+    }
+#ifdef XBMC_TRACK_EXCEPTIONS
   }
+  catch (const XbmcCommons::UncheckedException &e)
+  {
+    e.LogThrowMessage("CApplication::Create()");
+    MessageBox(NULL, "ERROR: Unable to create application. Exiting.", "XBMC: Error", MB_OK|MB_ICONERROR);
+    return 1;
+  }
+  catch (...)
+  {
+    CLog::Log(LOGERROR, "exception in CApplication::Create()");
+    MessageBox(NULL, "ERROR: Unable to create application. Exiting.", "XBMC: Error", MB_OK|MB_ICONERROR);
+    return 1;
+  }
+#endif
 
 #ifndef _DEBUG
   // we don't want to see the "no disc in drive" windows message box
   SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
 #endif
 
-  if (!g_application.CreateGUI())
+#ifdef XBMC_TRACK_EXCEPTIONS
+  try
   {
-    CStdString errorMsg;
-    errorMsg.Format("CApplication::CreateGUI() failed - Check log file for display errors");
-    MessageBox(NULL, errorMsg.c_str(), "XBMC: Error", MB_OK|MB_ICONERROR);
-    return 0;
+#endif
+    if (!g_application.CreateGUI())
+    {
+      MessageBox(NULL, "ERROR: Unable to create GUI. Exiting.", "XBMC: Error", MB_OK|MB_ICONERROR);
+      return 1;
+    }
+#ifdef XBMC_TRACK_EXCEPTIONS
+  }
+  catch (const XbmcCommons::UncheckedException &e)
+  {
+    e.LogThrowMessage("CApplication::CreateGUI()");
+    MessageBox(NULL, "ERROR: Unable to create GUI. Exiting.", "XBMC: Error", MB_OK|MB_ICONERROR);
+    return 1;
+  }
+  catch (...)
+  {
+    CLog::Log(LOGERROR, "exception in CApplication::CreateGUI()");
+    MessageBox(NULL, "ERROR: Unable to create GUI. Exiting.", "XBMC: Error", MB_OK|MB_ICONERROR);
+    return 1;
   }
+#endif
 
-  if (!g_application.Initialize())
+#ifdef XBMC_TRACK_EXCEPTIONS
+  try
   {
-    CStdString errorMsg;
-    errorMsg.Format("CApplication::Initialize() failed - Check log file and that it is writable");
-    MessageBox(NULL, errorMsg.c_str(), "XBMC: Error", MB_OK|MB_ICONERROR);
-    return 0;
+#endif
+    if (!g_application.Initialize())
+    {
+      MessageBox(NULL, "ERROR: Unable to Initialize. Exiting.", "XBMC: Error", MB_OK|MB_ICONERROR);
+      return 1;
+    }
+#ifdef XBMC_TRACK_EXCEPTIONS
+  }
+  catch (const XbmcCommons::UncheckedException &e)
+  {
+    e.LogThrowMessage("CApplication::Initialize()");
+    MessageBox(NULL, "ERROR: Unable to Initialize. Exiting.", "XBMC: Error", MB_OK|MB_ICONERROR);
+    return 1;
   }
+  catch (...)
+  {
+    CLog::Log(LOGERROR, "exception in CApplication::Initialize()");
+    MessageBox(NULL, "ERROR: Unable to Initialize. Exiting.", "XBMC: Error", MB_OK|MB_ICONERROR);
+    return 1;
+  }
+#endif
 
   g_application.Run();