Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Initialisiert eine neue Instanz der StackTrace-Klasse aus dem Rahmen des Aufrufers und zeichnet bei Bedarf Quellinformationen auf.
Namespace: System.Diagnostics
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Sub New ( _
fNeedFileInfo As Boolean _
)
'Usage
Dim fNeedFileInfo As Boolean
Dim instance As New StackTrace(fNeedFileInfo)
public StackTrace (
bool fNeedFileInfo
)
public:
StackTrace (
bool fNeedFileInfo
)
public StackTrace (
boolean fNeedFileInfo
)
public function StackTrace (
fNeedFileInfo : boolean
)
Parameter
- fNeedFileInfo
true, wenn Dateiname, Zeilennummer und Spaltennummer aufgezeichnet werden sollen, andernfalls false.
Hinweise
StackTrace wird mit dem aktuellen Thread des Aufrufers erstellt.
Beispiel
Im folgenden Codebeispiel werden verschiedene StackTrace-Konstruktormethoden veranschaulicht.
Public Sub Level2Method()
Try
Dim nestedClass As New ClassLevel3
nestedClass.Level3Method()
Catch e As Exception
Console.WriteLine(" Level2Method exception handler")
' Display the full call stack at this level.
Dim st1 As New StackTrace(True)
Console.WriteLine(" Stack trace for this level: {0}", _
st1.ToString())
' Build a stack trace from one frame, skipping the current
' frame and using the next frame.
Dim st2 As New StackTrace(New StackFrame(1, True))
Console.WriteLine(" Stack trace built with next level frame: {0}", _
st2.ToString())
' Build a stack trace skipping the current frame, and
' including all the other frames.
Dim st3 As New StackTrace(1, True)
Console.WriteLine(" Stack trace built from the next level up: {0}", _
st3.ToString())
Console.WriteLine()
Console.WriteLine(" ... throwing exception to next level ...")
Console.WriteLine("-------------------------------------------------")
Console.WriteLine()
Throw e
End Try
End Sub 'Level2Method
public void Level2Method()
{
try
{
ClassLevel3 nestedClass = new ClassLevel3();
nestedClass.Level3Method();
}
catch (Exception e)
{
Console.WriteLine(" Level2Method exception handler");
// Display the full call stack at this level.
StackTrace st1 = new StackTrace(true);
Console.WriteLine(" Stack trace for this level: {0}",
st1.ToString());
// Build a stack trace from one frame, skipping the current
// frame and using the next frame.
StackTrace st2 = new StackTrace(new StackFrame(1, true));
Console.WriteLine(" Stack trace built with next level frame: {0}",
st2.ToString());
// Build a stack trace skipping the current frame, and
// including all the other frames.
StackTrace st3 = new StackTrace(1, true);
Console.WriteLine(" Stack trace built from the next level up: {0}",
st3.ToString());
Console.WriteLine();
Console.WriteLine(" ... throwing exception to next level ...");
Console.WriteLine("-------------------------------------------------\n");
throw e;
}
}
void Level2Method()
{
try
{
ClassLevel3^ nestedClass = gcnew ClassLevel3;
nestedClass->Level3Method();
}
catch ( Exception^ e )
{
Console::WriteLine( " Level2Method exception handler" );
// Display the full call stack at this level.
StackTrace^ st1 = gcnew StackTrace( true );
Console::WriteLine( " Stack trace for this level: {0}", st1->ToString() );
// Build a stack trace from one frame, skipping the
// current frame and using the next frame.
StackTrace^ st2 = gcnew StackTrace( gcnew StackFrame( 1,true ) );
Console::WriteLine( " Stack trace built with next level frame: {0}", st2->ToString() );
// Build a stack trace skipping the current frame, and
// including all the other frames.
StackTrace^ st3 = gcnew StackTrace( 1,true );
Console::WriteLine( " Stack trace built from the next level up: {0}", st3->ToString() );
Console::WriteLine();
Console::WriteLine( " ... throwing exception to next level ..." );
Console::WriteLine( "-------------------------------------------------\n" );
throw e;
}
}
public void Level2Method() throws System.Exception
{
try {
ClassLevel3 nestedClass = new ClassLevel3();
nestedClass.Level3Method();
}
catch (System.Exception e) {
Console.WriteLine(" Level2Method exception handler");
// Display the full call stack at this level.
StackTrace st1 = new StackTrace(true);
Console.WriteLine(" Stack trace for this level: {0}",
st1.ToString());
// Build a stack trace from one frame, skipping the current
// frame and using the next frame.
StackTrace st2 = new StackTrace(new StackFrame(1, true));
Console.WriteLine(" Stack trace built with next level frame: {0}",
st2.ToString());
// Build a stack trace skipping the current frame, and
// including all the other frames.
StackTrace st3 = new StackTrace(1, true);
Console.WriteLine(" Stack trace built from the next level up: {0}",
st3.ToString());
Console.WriteLine();
Console.WriteLine(" ... throwing exception to next level...");
Console.WriteLine("--------------------------------------------"
+ "-----\n");
throw e;
}
} //Level2Method
Plattformen
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
StackTrace-Klasse
StackTrace-Member
System.Diagnostics-Namespace