Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

StackFrame.StackFrame(Int32, Boolean) Constructor

Initializes a new instance of the StackFrame class that corresponds to a frame above the current stack frame, optionally capturing source information.

Namespace: System.Diagnostics
Assembly: mscorlib (in mscorlib.dll)

public StackFrame (
	int skipFrames,
	bool fNeedFileInfo
)
public StackFrame (
	int skipFrames, 
	boolean fNeedFileInfo
)
public function StackFrame (
	skipFrames : int, 
	fNeedFileInfo : boolean
)
Not applicable.

Parameters

skipFrames

The number of frames up the stack to skip.

fNeedFileInfo

true to capture the file name, line number, and column number of the stack frame; otherwise, false.

The following example demonstrates the use of the StackFrame(Int32,Boolean) constructor.

public void Level2Method()
{
   try 
   {
      ClassLevel3 nestedClass = new ClassLevel3();
      nestedClass.Level3Method();

   }
   catch (Exception e) 
   {
      Console.WriteLine(" Level2Method exception handler");

      // Display the full call stack at this level.
      StackTrace st1 = new StackTrace(true);
      Console.WriteLine(" Stack trace for this level: {0}",
         st1.ToString());

      // Build a stack trace from one frame, skipping the current
      // frame and using the next frame.
      StackTrace st2 = new StackTrace(new StackFrame(1, true));
      Console.WriteLine(" Stack trace built with next level frame: {0}",
         st2.ToString());

      // Build a stack trace skipping the current frame, and
      // including all the other frames.
      StackTrace st3 = new StackTrace(1, true);
      Console.WriteLine(" Stack trace built from the next level up: {0}",
         st3.ToString());

      Console.WriteLine();
      Console.WriteLine("   ... throwing exception to next level ...");
      Console.WriteLine("-------------------------------------------------\n");
      throw e;
   }
}

public void Level2Method() throws System.Exception
{
    try {
        ClassLevel3 nestedClass = new ClassLevel3();
        nestedClass.Level3Method();
    }
    catch (System.Exception e) {
        Console.WriteLine(" Level2Method exception handler");

        // Display the full call stack at this level.
        StackTrace st1 = new StackTrace(true);
        Console.WriteLine(" Stack trace for this level: {0}", 
            st1.ToString());

        // Build a stack trace from one frame, skipping the current
        // frame and using the next frame.
        StackTrace st2 = new StackTrace(new StackFrame(1, true));
        Console.WriteLine(" Stack trace built with next level frame: {0}",
            st2.ToString());

        // Build a stack trace skipping the current frame, and
        // including all the other frames.
        StackTrace st3 = new StackTrace(1, true);
        Console.WriteLine(" Stack trace built from the next level up: {0}",
            st3.ToString());
        Console.WriteLine();
        Console.WriteLine(" ... throwing exception to next level...");
        Console.WriteLine("--------------------------------------------"
            + "-----\n");
        throw e;
    }
} //Level2Method

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft