Exemplo n.º 1
0
        public void Handle(Exception exception, MethodBase currentMethod, bool run)
        {
            try
            {
                if (currentMethod.DeclaringType != null)
                {
                    var exceptionFrom = GetExceptionFrom(currentMethod.Name,
                                                         OnlyClassName(currentMethod.DeclaringType.ToString()),
                                                         Application.ProductName,
                                                         Application.ProductVersion);

                    // LoadValues(exceptions)
                    Values.ExceptionFrom    = exceptionFrom;
                    Values.ExceptionType    = exception.GetType().ToString();
                    Values.ExceptionMessage = exception.Message;

                    var exceptionForm = new ExceptionForm();
                    exceptionForm.Values = Values;

                    if (run == false)
                    {
                        if (exceptionForm.InvokeRequired)
                        {
                            exceptionForm.BeginInvoke((MethodInvoker)exceptionForm.Show);
                        }
                        else
                        {
                            _exceptionForm = exceptionForm;
                            var appThread = new Thread(LaunchExceptionForm);
                            appThread.SetApartmentState(ApartmentState.STA);
                            appThread.Start();
                        }
                    }
                    else
                    {
                        Application.Run(exceptionForm);
                    }

                    // Gets the exception and saves to the Exceptions variable
                    Values.Exceptions += BuildExceptionMessage(Values.ExceptionFrom, Values.ExceptionType,
                                                               Values.ExceptionMessage, "Automated collection");
                }
            }

            // Do not use ExceptionForm
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }