Esempio n. 1
0
        /// <summary>
        /// Handles an exception through the Unhandled Exception window.
        /// </summary>
        /// <param name="ex">Exception to display</param>
        private static void HandleUnhandledException(Exception ex)
        {
            if (Debugger.IsAttached)
            {
                return;
            }

            if (s_errorWindowIsShown)
            {
                return;
            }

            s_errorWindowIsShown = true;

            try
            {
                // Some exceptions may be thrown on a worker thread so we need to invoke them to the UI thread,
                // if we are already on the UI thread nothing changes
                if (s_mainWindow != null && s_mainWindow.InvokeRequired)
                {
                    Dispatcher.Invoke(() => HandleUnhandledException(ex));
                    return;
                }

                using (UnhandledExceptionWindow form = new UnhandledExceptionWindow(ex))
                {
                    if (s_mainWindow != null && !s_mainWindow.IsDisposed)
                    {
                        form.ShowDialog(s_mainWindow);
                    }
                    else
                    {
                        form.ShowDialog();
                    }
                }

                // Notify Gooogle Analytics about ending via the Unhandled Exception window
                GAnalyticsTracker.TrackEnd(typeof(Program));
            }
            catch (Exception e)
            {
                StringBuilder messageBuilder = new StringBuilder();
                messageBuilder
                .AppendLine(@"An error occurred and EVEMon was unable to handle the error message gracefully.")
                .AppendLine()
                .AppendLine($"The exception encountered was '{e.Message}'.");

                if (ex.GetBaseException().Message != e.Message)
                {
                    messageBuilder
                    .AppendLine()
                    .AppendLine($"The original exception encountered was '{ex.GetBaseException().Message}'.");
                }

                messageBuilder
                .AppendLine()
                .AppendLine(@"Please report this on the EVEMon forums.");

                if (EveMonClient.IsDebugBuild)
                {
                    messageBuilder.AppendLine().AppendLine(UnhandledExceptionWindow.GetRecursiveStackTrace(ex));
                }

                MessageBox.Show(messageBuilder.ToString(), @"EVEMon Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }

            Environment.Exit(1);
        }
Esempio n. 2
0
        /// <summary>
        /// Handles an exception through the Unhandled Exception window.
        /// </summary>
        /// <param name="ex">Exception to display</param>
        private static void HandleUnhandledException(Exception ex)
        {
            if (Debugger.IsAttached)
            {
                return;
            }

            if (s_errorWindowIsShown)
            {
                return;
            }

            s_errorWindowIsShown = true;

            try
            {
                // Some exceptions may be thrown on a worker thread so we need to invoke them to the UI thread,
                // if we are already on the UI thread nothing changes
                if (s_mainWindow != null && s_mainWindow.InvokeRequired)
                {
                    Dispatcher.Invoke(() => HandleUnhandledException(ex));
                    return;
                }

                using (UnhandledExceptionWindow form = new UnhandledExceptionWindow(ex))
                {
                    if (s_mainWindow != null && !s_mainWindow.IsDisposed)
                    {
                        form.ShowDialog(s_mainWindow);
                    }
                    else
                    {
                        form.ShowDialog();
                    }
                }

                // Notify Gooogle Analytics about ending via the Unhandled Exception window
                GAnalyticsTracker.TrackEnd(typeof(Program));
            }
            catch (Exception e)
            {
                StringBuilder messageBuilder = new StringBuilder();
                messageBuilder.AppendLine(string.Format(Properties.Resources.ErrorUnhandled,
                                                        e.Message));
                if (ex.GetBaseException().Message != e.Message)
                {
                    messageBuilder.AppendLine(string.Format(Properties.Resources.
                                                            ErrorUnhandledBase, ex.GetBaseException().Message));
                }
                messageBuilder.AppendLine(Properties.Resources.ErrorUnhandledEnd);
                if (EveMonClient.IsDebugBuild)
                {
                    messageBuilder.AppendLine().AppendLine(UnhandledExceptionWindow.
                                                           GetRecursiveStackTrace(ex));
                }
                MessageBox.Show(messageBuilder.ToString(), @"EVEMon Error", MessageBoxButtons.
                                OK, MessageBoxIcon.Error);
            }

            Environment.Exit(1);
        }