TESVSnip.Program.CurrentDomainUnhandledException C# (CSharp) Method

CurrentDomainUnhandledException() public static method

public static CurrentDomainUnhandledException ( object sender, UnhandledExceptionEventArgs e ) : void
sender object
e System.UnhandledExceptionEventArgs
return void
        public static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            try
            {
                Exception ex = (Exception)e.ExceptionObject;

                // Since we can't prevent the app from terminating, log this to the event log.
                if (!EventLog.SourceExists("ThreadException"))
                {
                    EventLog.CreateEventSource("ThreadException", "Application");
                }

                string errMsg =
                  "Message: " + ex.Message +
                  Environment.NewLine +
                  Environment.NewLine +
                  "StackTrace: " + ex.StackTrace +
                  Environment.NewLine +
                  Environment.NewLine +
                  "Source: " + ex.Source +
                  Environment.NewLine +
                  Environment.NewLine +
                  "GetType: " + ex.GetType().ToString();

                Clipboard.SetDataObject(errMsg, true);

                // Create an EventLog instance and assign its source.
                EventLog myLog = new EventLog();
                myLog.Source = "ThreadException";
                myLog.WriteEntry(errMsg );

                MessageBox.Show(errMsg, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            finally
            {
                Application.Exit();
            }
        }