コード例 #1
0
        public ErrorDialog(Exception ex, bool submitError)
        {
            SplashScreen.CloseAll();

            IsHandlingError = true;

            BringToFrontEx();

            ControlAdded   += control_ControlAdded;
            ControlRemoved += control_ControlRemoved;

            InitializeComponent();

            StringBuilder errBuf = new StringBuilder();

            foreach (string line in ex.ToString().Split('\n'))
            {
                if (line.Contains("Microsoft.Xna.Framework.Game.Tick"))
                {
                    break;
                }
                else
                {
                    errBuf.AppendLine(line.Trim('\r'));
                }
            }
            string errorString = errBuf.ToString();

            textBoxDetails.Text = errorString;

            StackTrace trace = new StackTrace(ex);

            if (submitError)
            {
                worker         = new BackgroundWorker();
                worker.DoWork += delegate
                {
                    OsuError osuError = new OsuError();

                    StringBuilder report = new StringBuilder();
                    foreach (StackFrame frame in DebugHelper.FilterFrames(trace.GetFrames()))
                    {
                        report.AppendLine("METHOD " + frame.GetMethod());
                        report.AppendLine("Module " + frame.GetMethod().Module);
                        report.AppendLine("Il-Offset: " + frame.GetILOffset() + " Jit-offset: " + frame.GetNativeOffset());
                        report.AppendLine("IL code ");
                        report.AppendLine(DebugHelper.OpcodeToIL(frame.GetMethod()));
                        report.AppendLine();
                        MethodBody MB = frame.GetMethod().GetMethodBody();
                        List <ExceptionHandlingClause> Exceptions = MB != null ? new List <ExceptionHandlingClause>(MB.ExceptionHandlingClauses) : null;

                        if (Exceptions == null || Exceptions.Count == 0)
                        {
                            continue;
                        }
                        report.AppendLine("possible caught exceptions:");

                        //we don't use toString as this method assumes FilterOffset!=null
                        //(bad ms code)
                        foreach (ExceptionHandlingClause E in Exceptions)
                        {
                            try
                            {
                                report.AppendLine(String.Format("catchType:{0}, Flags:{1}, HandlerLength:{2}, " + "HandlerOffset:{3}, TryLength:{4}, TryOffset:{5}", E.CatchType, E.Flags, E.HandlerLength, E.HandlerOffset, E.TryLength, E.TryOffset));
                            }
                            catch
                            {
                                report.AppendLine("Unknown ExceptionType");
                            }
                        }
                        report.AppendLine("ENDMETHOD");
                        report.AppendLine();
                    }

                    osuError.ILTrace    = report.ToString();
                    osuError.StackTrace = errorString;
                    osuError.Exception  = ex != null?ex.GetType().ToString() : string.Empty;

                    ErrorSubmission.Submit(osuError);
                };
                worker.RunWorkerAsync();
            }
        }