System.Diagnostics.StackTrace Class

Assembly: Mscorlib.dll
Namespace: System.Diagnostics
Summary
Acquires a stack trace.
C# Syntax:
[Serializable]
public class StackTrace
See also:
System.Diagnostics Namespace

System.Diagnostics.StackTrace Member List:

Public Constructors
ctor #1 Overloaded:
.ctor()

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the StackTrace class from the current location, in a caller's frame.
ctor #2 Overloaded:
.ctor(bool fNeedFileInfo)

Initializes a new instance of the StackTrace class from the current location, in a caller's frame, optionally capturing source information.
ctor #3 Overloaded:
.ctor(Exception e)

Initializes a new instance of the StackTrace class.
ctor #4 Overloaded:
.ctor(int skipFrames)

Initializes a new instance of the StackTrace class from the current location, in a caller's frame, optionally skipping the given number of frames.
ctor #5 Overloaded:
.ctor(StackFrame frame)

Initializes a new instance of the StackTrace class that contains a single frame.
ctor #6 Overloaded:
.ctor(Exception e, bool fNeedFileInfo)

Initializes a new instance of the StackTrace class, using the provided exception object, optionally capturing source information.
ctor #7 Overloaded:
.ctor(Exception e, int skipFrames)

Initializes a new instance of the StackTrace class using the provided exception object, optionally skipping the given number of frames.
ctor #8 Overloaded:
.ctor(int skipFrames, bool fNeedFileInfo)

Initializes a new instance of the StackTrace class from the current location, in a caller's frame, optionally skipping the given number of frames and capturing source information.
ctor #9 Overloaded:
.ctor(Thread targetThread, bool needFileInfo)

Initializes a new instance of the StackTrace class for another thread, optionally capturing source information.
ctor #10 Overloaded:
.ctor(Exception e, int skipFrames, bool fNeedFileInfo)

Initializes a new instance of the StackTrace class using the provided exception object, optionally skipping the given number of frames and capturing source information.
Public Fields
METHODS_TO_SKIP Defines the default for the number of methods to omit from the stack trace. This field is constant.
Public Properties
FrameCount Read-only

Gets the number of frames in the stack trace.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetFrame Gets the specified stack frame.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString Overridden:
Builds a readable representation of the stack trace.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Diagnostics.StackTrace Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the StackTrace class from the current location, in a caller's frame.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public StackTrace();

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the StackTrace class from the current location, in a caller's frame, optionally capturing source information.
C# Syntax:
public StackTrace(
   bool fNeedFileInfo
);
Parameters:

fNeedFileInfo

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

Return to top


Overloaded ctor #3
Summary
Initializes a new instance of the StackTrace class.
C# Syntax:
public StackTrace(
   Exception e
);
Parameters:

e

The exception object from which to construct the stack trace.

Exceptions
Exception Type Condition
ArgumentNullException The parameter e is null.

Return to top


Overloaded ctor #4
Summary
Initializes a new instance of the StackTrace class from the current location, in a caller's frame, optionally skipping the given number of frames.
C# Syntax:
public StackTrace(
   int skipFrames
);
Parameters:

skipFrames

The number of frames up the stack from which to start the trace.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException The skipFrames parameter is negative.

Return to top


Overloaded ctor #5
Summary
Initializes a new instance of the StackTrace class that contains a single frame.
C# Syntax:
public StackTrace(
   StackFrame frame
);
Parameters:

frame

The frame that the StackTrace object should contain.

Remarks
Use this constructor when you do not want the overhead of a full stack trace.

Return to top


Overloaded ctor #6
Summary
Initializes a new instance of the StackTrace class, using the provided exception object, optionally capturing source information.
C# Syntax:
public StackTrace(
   Exception e,
   bool fNeedFileInfo
);
Parameters:

e

The exception object from which to construct the stack trace.

fNeedFileInfo

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

Exceptions
Exception Type Condition
ArgumentNullException The parameter e is null.
Remarks
The resulting stack trace describes the stack at the time of the exception.

Return to top


Overloaded ctor #7
Summary
Initializes a new instance of the StackTrace class using the provided exception object, optionally skipping the given number of frames.
C# Syntax:
public StackTrace(
   Exception e,
   int skipFrames
);
Parameters:

e

The exception object from which to construct the stack trace.

skipFrames

The number of frames up the stack from which to start the trace.

Exceptions
Exception Type Condition
ArgumentNullException The parameter e is null.
ArgumentOutOfRangeException The skipFrames parameter is negative.
Remarks
The resulting stack trace describes the stack at the time of the exception.

Return to top


Overloaded ctor #8
Summary
Initializes a new instance of the StackTrace class from the current location, in a caller's frame, optionally skipping the given number of frames and capturing source information.
C# Syntax:
public StackTrace(
   int skipFrames,
   bool fNeedFileInfo
);
Parameters:

skipFrames

The number of frames up the stack from which to start the trace.

fNeedFileInfo

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

Exceptions
Exception Type Condition
ArgumentOutOfRangeException The skipFrames parameter is negative.

Return to top


Overloaded ctor #9
Summary
Initializes a new instance of the StackTrace class for another thread, optionally capturing source information.
C# Syntax:
public StackTrace(
   Thread targetThread,
   bool needFileInfo
);
Parameters:

targetThread

The thread whose stack trace is requested.

needFileInfo

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

Exceptions
Exception Type Condition
ThreadStateException The thread targetThread is not suspended.

Return to top


Overloaded ctor #10
Summary
Initializes a new instance of the StackTrace class using the provided exception object, optionally skipping the given number of frames and capturing source information.
C# Syntax:
public StackTrace(
   Exception e,
   int skipFrames,
   bool fNeedFileInfo
);
Parameters:

e

The exception object from which to construct the stack trace.

skipFrames

The number of frames up the stack from which to start the trace.

fNeedFileInfo

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

Exceptions
Exception Type Condition
ArgumentNullException The parameter e is null.
ArgumentOutOfRangeException The skipFrames parameter is negative.
Remarks
The resulting stack trace describes the stack at the time of the exception.

Return to top


Field: METHODS_TO_SKIP
Summary
Defines the default for the number of methods to omit from the stack trace. This field is constant.
C# Syntax:
public const int METHODS_TO_SKIP;
Remarks
The default value for the number of methods to skip at the beginning of the stack trace. The value of this constant is zero.

Return to top


Property: FrameCount (read-only)
Summary
Gets the number of frames in the stack trace.
C# Syntax:
public virtual int FrameCount {get;}

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~StackTrace();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetFrame(
   int index
)
Summary
Gets the specified stack frame.
C# Syntax:
public virtual StackFrame GetFrame(
   int index
);
Parameters:

index

The index of the stack frame requested.

Return Value:
The specified stack frame.
Remarks
Stack frames are numbered starting at zero, which is the last stack frame pushed.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: ToString()
Summary
Builds a readable representation of the stack trace.
C# Syntax:
public override string ToString();
Return Value:
A readable representation of the stack trace.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.