Beispiel #1
0
        // Initialize this object with a complete stack trace.
        private void Initialize(Exception e, int skipFrames, bool needFileInfo)
        {
            if (e == null)
            {
                // Get the total number of frames on the stack at present.
                int totalFrames = StackFrame.InternalGetTotalFrames();

                // Validate "skipFrames", and then account for the
                // extra frames that we have pushed while getting here.
                if (skipFrames < 0 || skipFrames > (totalFrames - 2))
                {
                    skipFrames = 0;
                }
                skipFrames += 2;

                // Create the frame array.
                totalFrames -= 2;
                numFrames    = totalFrames;
                frames       = new StackFrame [totalFrames];

                // Fill the frame array.
                int posn = 0;
                while (posn < totalFrames)
                {
                    frames[posn] =
                        new StackFrame(posn + skipFrames, needFileInfo);
                    ++posn;
                }
            }
            else
            {
                // Unpack an exception's "packed" stack trace
                // to determine where it was thrown from.
                UnpackStackTrace(e.GetPackedStackTrace(),
                                 skipFrames, needFileInfo);
            }
        }