/[AnywhereTS-MSSQL]/trunk/TSControlPanel/Program.cs
ViewVC logotype

Diff of /trunk/TSControlPanel/Program.cs

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

--- trunk/TSControlPanel/Program.cs	2012/07/12 19:07:58	65
+++ trunk/TSControlPanel/Program.cs	2012/07/12 19:40:36	68
@@ -2,6 +2,8 @@
 using System.Collections.Generic;
 using System.Windows.Forms;
 using System.Data.SqlClient;
+using System.Collections;
+using System.Text;
 
 namespace AnywhereTS
 {
@@ -33,27 +35,51 @@
         }
         static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
         {
+            DialogResult result = DialogResult.Cancel;
             Exception e = (Exception)args.ExceptionObject;
             if (e == null)
             {
-                Logging.ATSAdminLog.Error("Encountered unhandled Exception, but the exception was null");
+                Logging.TSControlPanelLog.Error("Encountered unhandled Exception, but the exception was null");
                 return;
             }
             if (e.GetType() == typeof(SqlException))
             {
                 SqlException sql_ex = (e as SqlException);
+                Stack stack = new Stack();
                 using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", sql_ex.Number.ToString(), sql_ex.Message, System.Environment.NewLine, sql_ex.ToString())))
                 {
-                    Logging.ATSAdminLog.Error("Encountered unhandled SqlException");
+                    stack = log4net.NDC.CloneStack();
+                    Logging.TSControlPanelLog.Error("Encountered unhandled SqlException");
                 }
+                List<object> strs = new List<object>(stack.ToArray());
+                strs.Reverse();
+                StringBuilder builder = new StringBuilder();
+                foreach (object str in strs) { builder.AppendLine(str.ToString()); }
+                result = ShowAbortRetryIgnoreDialog("Encountered unhandled Exception", builder.ToString());
+                if (result == DialogResult.Abort)
+                    Application.Exit();
             }
             else
             {
+                Stack stack = new Stack();
                 using (log4net.NDC.Push(string.Format("Exception: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
                 {
-                    Logging.ATSAdminLog.Error("Encountered unhandled Exception");
-                }
+                    stack = log4net.NDC.CloneStack();
+                    Logging.TSControlPanelLog.Error("Encountered unhandled Exception");
+                }                
+                List<object> strs = new List<object>(stack.ToArray());
+                strs.Reverse();
+                StringBuilder builder = new StringBuilder();
+                foreach (object str in strs) { builder.AppendLine(str.ToString()); }
+                result = ShowAbortRetryIgnoreDialog("Encountered unhandled Exception", builder.ToString());
+                if (result == DialogResult.Abort)
+                    Application.Exit();
             }
         }
+        // Creates the error message and displays it.
+        private static DialogResult ShowAbortRetryIgnoreDialog(string title, string message)
+        {
+            return MessageBox.Show(message, title, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
+        }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22