/[EmuXPortal]/branches/mono/EmuXPortal/Form1.cs
ViewVC logotype

Diff of /branches/mono/EmuXPortal/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/EmuXPortal/Form1.cs	2014/08/05 05:19:39	241
+++ trunk/EmuXPortal/Form1.cs	2014/08/05 05:57:55	243
@@ -28,9 +28,43 @@
         IEmuConfig CurrentSelectedRom = null;
         PlatformControl CurrentPlatformControl = null;
         GameControl CurrentGameControl = null;
+
+        #region unhandled exception support
+        static void Application_Unhandled_ThreadException(object sender, ThreadExceptionEventArgs e)
+        {
+            UnhandledExceptionEventArgs uea = new UnhandledExceptionEventArgs(e.Exception, false);
+            UnhandledExceptionEventHandler(sender, uea);
+        }
+        static void UnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs args)
+        {            
+            Exception ex = (args.ExceptionObject as Exception);
+            if (sender == null)
+            {
+                gLog.Error.WriteLine("Caught an unhandled exception from an unkown source");
+            }
+            else
+            {
+                gLog.Error.WriteLine("Caught an unhandled exception from type: {0}", sender.GetType().Name);
+            }
+
+            if (ex == null)
+            {
+                gLog.Error.WriteLine("The exception object was null -- it probably is not derived from System.Exception");
+            }
+            else
+            {
+                ex = ex.GetBaseException();
+                gLog.Error.WriteLine("{0}:", ex.GetType().Name);
+                gLog.Verbose.Error.WriteLine(ex.ToString());
+            }            
+            
+        }
+        #endregion
         public Form1()
         {
-            InitializeComponent();           
+            InitializeComponent();
+
+         
             #region logging support
             string log_path = Application.StartupPath;
             string log_filename = string.Format("{0}.log", typeof(Form1).Assembly.GetName().Name);
@@ -59,9 +93,18 @@
 #endif
             #endregion
 
+            #region unhandled exception support
+            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionEventHandler);
+            Application.ThreadException += Application_Unhandled_ThreadException;
+            #endregion
+
             platform_flow.Dock = DockStyle.Fill;
             rom_flow.Dock = DockStyle.Fill;
         }
+
+       
+
+      
 #region logging support
         StringBuilder log_flusher = new StringBuilder();
         void Log_OnFlush(object sender, LoggerOnFlushEventArgs e) { OnLogFlush(e.Buffer); }

 

  ViewVC Help
Powered by ViewVC 1.1.22