Environment.StackTrace
Environment.StackTrace
Environment.StackTrace
Environment.StackTrace
Property
Definition
Gets current stack trace information.
public:
static property System::String ^ StackTrace { System::String ^ get(); };
public static string StackTrace { get; }
member this.StackTrace : string
Public Shared ReadOnly Property StackTrace As String
Property Value
Examples
The following example demonstrates the StackTrace property.
// Sample for the Environment::StackTrace property
using namespace System;
int 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
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
Imports System
Class Sample
Public Shared Sub Main()
Console.WriteLine()
Console.WriteLine("StackTrace: '{0}'", Environment.StackTrace)
End Sub 'Main
End Class '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()'
'
Remarks
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.
Note
For a hierarchical view of the stack trace information by class, use the StackTrace class.
The StackTrace property formats the stack trace information for each method call as follows:
"at FullClassName
.MethodName
(MethodParams
) in FileName
:line LineNumber
"
The literal "at" is preceded by three spaces, and the entire substring starting with "in" is omitted if debug symbols are not available. The placeholders, FullClassName
, MethodName
, MethodParams
, FileName
, and LineNumber
, are replaced by actual values, and are defined as follows:
FullClassName
The full name of the class, including the namespace.
MethodName
The name of the method.
MethodParams
The list of parameter type/name pairs. Each pair is separated by a comma (","). This information is omitted if MethodName
takes no 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 Environment.NewLine string terminates each line of the stack trace.
Security
EnvironmentPermission
for full access to the resource protected by the permission. Associated enumeration: Unrestricted
Applies to
Feedback
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.
Loading feedback...