OSDN Git Service

Added Handler for hidden exceptions to Log into common logger
authorDouglas R. Miles <logicmoo@gmail.com>
Thu, 24 Sep 2009 23:13:16 +0000 (23:13 +0000)
committerDouglas R. Miles <logicmoo@gmail.com>
Thu, 24 Sep 2009 23:13:16 +0000 (23:13 +0000)
RadegastInstance CleanUp() protect against null pointers

git-svn-id: https://radegast.googlecode.com/svn/trunk@268 f7a694da-4d33-11de-9ad6-1127a62b9fcd

Radegast/Core/RadegastInstance.cs

index 7f626c8..bfeeeca 100644 (file)
@@ -32,6 +32,7 @@ using System;
 using System.Collections.Generic;\r
 using System.IO;\r
 using System.Reflection;\r
+using System.Threading;\r
 using System.Windows.Forms;\r
 using Radegast.Commands;\r
 using Radegast.Netcom;\r
@@ -149,8 +150,9 @@ namespace Radegast
         public RadegastInstance(GridClient client0)\r
         {\r
             // incase something else calls GlobalInstance while we are loading\r
-            globalInstance = this; \r
-\r
+            globalInstance = this;\r
+            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);\r
+            Application.ThreadException += HandleThreadException;\r
             client = client0;\r
 \r
             // Are we running mono?\r
@@ -216,28 +218,52 @@ namespace Radegast
 \r
             lock (PluginsLoaded)\r
             {\r
-                PluginsLoaded.ForEach(plug =>\r
+                 List<IRadegastPlugin> unload = new List<IRadegastPlugin>(PluginsLoaded);\r
+                 unload.ForEach(plug =>\r
                 {\r
+                    PluginsLoaded.Remove(plug);\r
                     try\r
                     {\r
                         plug.StopPlugin(this);\r
                     }\r
-                    catch (Exception) { }\r
+                    catch (Exception ex)\r
+                    {\r
+                        Logger.Log("ERROR in Shutdown Plugin: " + plug + " because " + ex, Helpers.LogLevel.Debug, ex);\r
+                    }\r
                 });\r
             }\r
 \r
-            movement.Dispose();\r
-            movement = null;\r
-            commandsManager.Dispose();\r
-            commandsManager = null;\r
-            ContextActionManager.Dispose();\r
-            ContextActionManager = null;\r
-            mediaManager.Dispose();\r
-            mediaManager = null;\r
-            state.Dispose();\r
-            state = null;\r
-            netcom.Dispose();\r
-            netcom = null;\r
+            if (movement != null)\r
+            {\r
+                movement.Dispose();\r
+                movement = null;\r
+            }\r
+            if (commandsManager != null)\r
+            {\r
+                commandsManager.Dispose();\r
+                commandsManager = null;\r
+            }\r
+            if (ContextActionManager != null)\r
+            {\r
+                ContextActionManager.Dispose();\r
+                ContextActionManager = null;\r
+            }\r
+            if (mediaManager != null)\r
+            {\r
+                mediaManager.Dispose();\r
+                mediaManager = null;\r
+            }\r
+            if (state != null)\r
+            {\r
+                state.Dispose();\r
+                state = null;\r
+            }\r
+            if (netcom != null)\r
+            {\r
+                netcom.Dispose();\r
+                netcom = null;\r
+            }\r
+\r
             Logger.Log("RadegastInstance finished cleaning up.", Helpers.LogLevel.Debug);\r
         }\r
 \r
@@ -484,5 +510,10 @@ namespace Radegast
         {\r
             get { return tabsConsole; }\r
         }\r
+\r
+        public void HandleThreadException(object sender, ThreadExceptionEventArgs e)\r
+        {\r
+            Logger.Log("Unhandled Thread Exception: "+e.Exception + " in " +sender,Helpers.LogLevel.Error,client);\r
+        }\r
     }\r
 }\r