Beispiel #1
0
        /// <summary>
        /// Handles cross thread exceptions, that are unrecoverable
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            // Create Trace Log
            string        FileName = Path.Combine(Application.StartupPath, "ExceptionLog_" + DateTime.Now.ToString("yyyyMMdd_HHmm") + ".txt");
            Exception     Ex       = e.ExceptionObject as Exception;
            ExceptionForm EForm    = new ExceptionForm(Ex, false);

            try
            {
                // Try to generate a trace log
                GenerateExceptionLog(FileName, Ex);

                // Display the Exception Form
                EForm.Message = "An unhandled exception was thrown while trying to preform the requested task.\r\n"
                                + "A trace log was generated the program root folder, to "
                                + "assist with debugging, and getting help with this error.";
                EForm.TraceLog = FileName;
            }
            catch
            {
                EForm.Message = "An unhandled exception was thrown while trying to preform the requested task.\r\n"
                                + "A trace log was unable to be generated because that threw another exception :(. The error message "
                                + "for the trace log was stored in the program error log for debugging purposes.";
            }
            finally
            {
                EForm.ShowDialog();
                Application.Exit();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Handles an exception on the main thread.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="t"></param>
        public static void OnThreadException(object sender, ThreadExceptionEventArgs t)
        {
            // Create Trace Log
            string FileName = Path.Combine(Application.StartupPath, "ExceptionLog_" + DateTime.Now.ToString("yyyyMMdd_HHmm") + ".txt");

            try
            {
                // Try to generate a trace log
                GenerateExceptionLog(FileName, t.Exception);
            }
            catch { }

            // Display the Exception Form
            ExceptionForm EForm = new ExceptionForm(t.Exception, true);

            EForm.Message = "An unhandled exception was thrown while trying to preform the requested task.\r\n"
                            + "If you click Continue, the application will attempt to ignore this error, and continue. "
                            + "If you click Quit, the application will close immediatly.";
            EForm.TraceLog = FileName;
            DialogResult Result = EForm.ShowDialog();

            // Kill the form on abort
            if (Result == DialogResult.Abort)
            {
                Application.Exit();
            }
        }