StackTrace Class

Represents a stack trace, which is an ordered collection of one or more stack frames.

System.Object
  System.Diagnostics.StackTrace

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

[<SerializableAttribute>]
[<ComVisibleAttribute(true)>]
[<SecurityPermissionAttribute(SecurityAction.InheritanceDemand, UnmanagedCode = true)>]
type StackTrace =  class end

The StackTrace type exposes the following members.

  NameDescription
Public methodStackTrace()Initializes a new instance of the StackTrace class from the caller's frame.
Public methodStackTrace(Boolean)Initializes a new instance of the StackTrace class from the caller's frame, optionally capturing source information.
Public methodStackTrace(Exception)Initializes a new instance of the StackTrace class using the provided exception object.
Public methodStackTrace(Int32)Initializes a new instance of the StackTrace class from the caller's frame, skipping the specified number of frames.
Public methodStackTrace(StackFrame)Initializes a new instance of the StackTrace class that contains a single frame.
Public methodStackTrace(Exception, Boolean)Initializes a new instance of the StackTrace class, using the provided exception object and optionally capturing source information.
Public methodStackTrace(Exception, Int32)Initializes a new instance of the StackTrace class using the provided exception object and skipping the specified number of frames.
Public methodStackTrace(Int32, Boolean)Initializes a new instance of the StackTrace class from the caller's frame, skipping the specified number of frames and optionally capturing source information.
Public methodStackTrace(Thread, Boolean) Obsolete. Initializes a new instance of the StackTrace class for a specific thread, optionally capturing source information. Do not use this constructor overload.
Public methodStackTrace(Exception, Int32, Boolean)Initializes a new instance of the StackTrace class using the provided exception object, skipping the specified number of frames and optionally capturing source information.
Top

  NameDescription
Public propertyFrameCountGets the number of frames in the stack trace.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetFrameGets the specified stack frame.
Public methodGetFramesReturns a copy of all stack frames in the current stack trace.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringBuilds a readable representation of the stack trace. (Overrides Object.ToString().)
Top

  NameDescription
Public fieldStatic memberMETHODS_TO_SKIPDefines the default for the number of methods to omit from the stack trace. This field is constant.
Top

StackTrace information will be most informative with Debug build configurations. By default, Debug builds include debug symbols, while Release builds do not. The debug symbols contain most of the file, method name, line number, and column information used in constructing StackFrame and StackTrace objects.

StackTrace might not report as many method calls as expected, due to code transformations that occur during optimization.

The following console application demonstrates how to create a simple StackTrace and iterate through its frames to obtain debugging and diagnostic information.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft