Ejemplo n.º 1
0
        /// <summary>
        /// Handle the UI exceptions by showing a dialog box, and asking the user whether or not they wish to abort execution.
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="t">ThreadExceptionEventArgs data</param>
        private static void MainForm_UIThreadException(object sender, ThreadExceptionEventArgs t)
        {
            DialogResult result = DialogResult.Cancel;

            try
            {
                string errorMsg = string.Format(CultureInfo.InvariantCulture, "Message : {0}\n\nStack Trace:\n{1}", t.Exception.Message, t.Exception.StackTrace);
                TQDebug.DebugEnabled = true;
                TQDebug.DebugWriteLine("UI Thread Exception");
                TQDebug.DebugWriteLine(errorMsg);
                result = MessageBox.Show(errorMsg, "Windows Forms Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, rightToLeft);
            }
            catch
            {
                try
                {
                    TQDebug.DebugEnabled = true;
                    TQDebug.DebugWriteLine("Fatal Windows Forms Error");
                    TQDebug.DebugWriteLine(string.Format(CultureInfo.InvariantCulture, "Message : {0}\n\nStack Trace:\n{1}", t.Exception.Message, t.Exception.StackTrace));
                    MessageBox.Show("Fatal Windows Forms Error", "Fatal Windows Forms Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, rightToLeft);
                }
                finally
                {
                    Application.Exit();
                }
            }

            // Exits the program when the user clicks Abort.
            if (result == DialogResult.Abort)
            {
                Application.Exit();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handle the UI exceptions by showing a dialog box, and asking the user whether or not they wish to abort execution.
        /// </summary>
        /// <remarks>NOTE: This exception cannot be kept from terminating the application - it can only log the event, and inform the user about it.</remarks>
        /// <param name="sender">sender object</param>
        /// <param name="e">UnhandledExceptionEventArgs data</param>
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            try
            {
                Exception ex = (Exception)e.ExceptionObject;

                TQDebug.DebugEnabled = true;
                TQDebug.DebugWriteLine("An application error occurred.");
                TQDebug.DebugWriteLine(string.Format(CultureInfo.InvariantCulture, "Message : {0}\n\nStack Trace:\n{1}", ex.Message, ex.StackTrace));
            }
            finally
            {
                Application.Exit();
            }
        }