public void InnerExceptionParserTest()
        {
            try {
                new ChkUtilsTestHelpers.Level1().DoIt();
            }
            catch (Exception e) {
                IExceptionParser parser = ExceptionParserFactory.Get(e);

                StringBuilder stackTrace = new StringBuilder();

                int index = 1;
                while (parser != null)
                {
                    // Test for order
                    switch (index++)
                    {
                    case 1:
                        this.TestRegularFields(parser, 0, "Exception", "Level1 Exception - highest level exception");
                        break;

                    case 2:
                        this.TestRegularFields(parser, 0, "FormatException", "Level2 Format Exception - middle exception");
                        break;

                    case 3:
                        this.TestRegularFields(parser, 0, "Exception", "Level3 Exception - most inner exception");
                        break;

                    default:
                        Assert.Fail("There should only be three levels");
                        break;
                    }

                    // For show
                    stackTrace.AppendLine(String.Format("{0} : {1}", parser.Info.Name, parser.Info.Msg));
                    parser.ExtraInfo.ForEach(
                        item => stackTrace.AppendLine(String.Format("{0}={1}", item.Name, item.Value)));
                    parser.GetStackFrames(true).ForEach(
                        item => stackTrace.AppendLine(item));
                    parser = parser.InnerParser;
                }

                Console.WriteLine(stackTrace.ToString());
            }
        }
        /// <summary>
        /// Use the IExceptionParser to parse out all of the exception and
        /// nested exceptions stack information to a multi line string
        /// </summary>
        /// <param name="parser">The parser to break down the exception</param>
        /// <param name="target">The target string builder for the stack string</param>
        public void FormatException(IExceptionParser parser, StringBuilder target)
        {
            // Get the first level parser for first level exception
            //IExceptionParser parser = ExceptionParserFactory.Get(e);
            while (parser != null) {
                // Exception Name and message
                target.AppendLine(String.Format("{0} : {1}", parser.Info.Name, parser.Info.Msg));

                // Extra info items added one per line
                parser.ExtraInfo.ForEach(
                    item => target.AppendLine(String.Format("{0}={1}", item.Name, item.Value)));

                // Stack trace items one per line
                parser.GetStackFrames(true).ForEach(
                    item => target.AppendLine(item));

                // Recurse to inner parser for inner exception
                parser = parser.InnerParser;
            }
        }
Exemple #3
0
        /// <summary>
        /// Use the IExceptionParser to parse out all of the exception and
        /// nested exceptions stack information to a multi line string
        /// </summary>
        /// <param name="parser">The parser to break down the exception</param>
        /// <param name="target">The target string builder for the stack string</param>
        public void FormatException(IExceptionParser parser, StringBuilder target)
        {
            // Get the first level parser for first level exception
            //IExceptionParser parser = ExceptionParserFactory.Get(e);
            while (parser != null)
            {
                // Exception Name and message
                target.AppendLine(String.Format("{0} : {1}", parser.Info.Name, parser.Info.Msg));

                // Extra info items added one per line
                parser.ExtraInfo.ForEach(
                    item => target.AppendLine(String.Format("{0}={1}", item.Name, item.Value)));

                // Stack trace items one per line
                parser.GetStackFrames(true).ForEach(
                    item => target.AppendLine(item));

                // Recurse to inner parser for inner exception
                parser = parser.InnerParser;
            }
        }