StackFrame Constructor (Boolean)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Initializes a new instance of the StackFrame class, optionally capturing source information.

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

public StackFrame(
	bool fNeedFileInfo
)

Parameters

fNeedFileInfo
Type: System.Boolean

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(Boolean) constructor. This code example is part of a larger example provided for the StackFrame class.

[STAThread]
static void Main()
 {
     ClassLevel1 mainClass = new ClassLevel1();

     try {
         mainClass.InternalMethod();
     }
     catch (Exception) {
        Console.WriteLine(" Main method exception handler");

        // Display file and line information, if available.
        StackTrace st = new StackTrace(new StackFrame(true));
        Console.WriteLine(" Stack trace for current level: {0}",
            st.ToString());
        Console.WriteLine(" File: {0}", 
           st.GetFrame(0).GetFileName());
        Console.WriteLine(" Line Number: {0}",
            st.GetFrame(0).GetFileLineNumber().ToString());

        Console.WriteLine();
        Console.WriteLine("-------------------------------------------------\n");
     }
 }

.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show: