Export (0) Print
Expand All

Environment.StackTrace Property

Gets current stack trace information.

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

public static string StackTrace { get; }
/** @property */
public static String get_StackTrace ()

public static function get StackTrace () : String

Property Value

A string containing stack trace information. This value can be String.Empty.

Exception typeCondition

ArgumentOutOfRangeException

The requested stack trace information is out of range.

The StackTrace property lists method calls in reverse chronological order, that is, the most recent method call is described first, and one line of stack trace information is listed for each method call on the stack. However, the StackTrace property might not report as many method calls as expected due to code transformations that occur during optimization.

The stack trace information for each method call is formatted as follows:

"at FullClassName. MethodName (MethodParams) in FileName :line LineNumber "

The literal "at" is preceded by three spaces, and the literals "in" and ":line" are omitted if debug symbols are not available. The placeholders, FullClassName, MethodName, MethodParms, FileName, and LineNumber, are replaced by actual values defined as follows:

FullClassName

The full name of the class, including the namespace.

MethodName

The name of the method.

MethodParms

The list of parameter type/name pairs. Each pair is separated by a comma (","). This information is omitted if MethodName takes zero parameters.

FileName

The name of the source file where the MethodName method is declared. This information is omitted if debug symbols are not available.

LineNumber

The number of the line in FileName that contains the source code from MethodName for the instruction that is on the call stack. This information is omitted if debug symbols are not available.

The following code example demonstrates the StackTrace property.

// Sample for the Environment.StackTrace property
using System;

class Sample 
{
    public static void Main() 
    {
    Console.WriteLine();
    Console.WriteLine("StackTrace: '{0}'", Environment.StackTrace);
    }
}
/*
This example produces the following results:

StackTrace: '   at System.Environment.GetStackTrace(Exception e)
   at System.Environment.GetStackTrace(Exception e)
   at System.Environment.get_StackTrace()
   at Sample.Main()'
*/

// Sample for the Environment.StackTrace property

import System.*;

class Sample
{
    public static void main(String[] args)
    {
        Console.WriteLine();
        Console.WriteLine("StackTrace: '{0}'", Environment.get_StackTrace());
    } //main
} //Sample

/*
This example produces the following results:

StackTrace: '   at System.Environment.GetStackTrace(Exception e)
   at System.Environment.GetStackTrace(Exception e)
   at System.Environment.get_StackTrace()
   at Sample.main(String args[])'
*/

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft