This entry is part of a series, The .NET Stack»
The StackTrace class is used to get a collection of StackFrames. A StackFrame contains information about a single point in the Stack. I’ll come back to that in a later post. The StackTrace class has multiple constructors with various parameters: –
The Default Constructor (no parameters)
Gets the current point in the stack in this function that you are calling it from.
fNeedFileInfo as Boolean
Whether we need the line numbers, file names etc in the stack trace (if available).
skipFrames as Integer
The number of frames to skip. 1 starts with the function that called this function. 2 starts with the one that called that function etc.
e as System.Exception
An Exception to build the stack trace for.
frame as StackFrame
A frame that this stack trace should contain.
targetThread as Thread
The thread to get the stack trace for.
Since there are 10 different constructors in .NET 3.5 at the time I am writing this, there are plenty of combinations that these can be used in.
The StackTrace class has several members that are of interest: –
The number of frames that this StackTrace contains.
GetFrame(index as Integer)
Get a frame at a certain position. See skipFrames (above) for what the position means.
Returns an array of the frames in the StackTrace.