public void ExceptionCaughtEventHandler(object sender, ExceptionCaughtEventArgs e)
 {
     buttonId++;
     Element element = e.Element;
     element.AppendChild(ExpectedSpan(element));
     element.AppendChild(ExceptionMessage(e.Exception.Message));
     element.AppendChild(StackTraceTogglingButton());
     element.AppendChild(StackTrace(e.Exception, e.Expression));
     
     EnsureDocumentHasTogglingScript(element);
 }
        public string markAsException(string fragment, string expression, string errorMessage)
        {
            var exception = new StackTraceSettingException(errorMessage);
            exception.StackTraceElements.AddRange(stackTraceElements);

            var document = new TestRig()
                                .ProcessFragment(fragment)
                                .GetXDocument();

            var element = document.Descendants("p").ToArray()[0];

            var eventArgs = new ExceptionCaughtEventArgs { Exception = exception, Expression = expression, Element = new Element(element) };
            new ExceptionRenderer().ExceptionCaughtEventHandler(this, eventArgs);

            //return element.ToString(SaveOptions.DisableFormatting);
            return element.ToString();
        }