StackFrame.ToString Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Génère une représentation lisible de la trace de la pile.
public:
override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String
Retours
Représentation lisible de la trace de la pile.
Exemples
L'exemple suivant illustre l'utilisation de la méthode ToString. Cet exemple de code fait partie d’un exemple plus grand fourni pour la StackFrame classe .
void InternalMethod()
{
try
{
ClassLevel2^ nestedClass = gcnew ClassLevel2;
nestedClass->Level2Method();
}
catch ( Exception^ e )
{
Console::WriteLine( " InternalMethod exception handler" );
// Build a stack trace from one frame, skipping the
// current frame and using the next frame. By
// default, file and line information are not displayed.
StackTrace^ st = gcnew StackTrace( gcnew StackFrame( 1 ) );
Console::WriteLine( " Stack trace for next level frame: {0}", st->ToString() );
Console::WriteLine( " Stack frame for next level: " );
Console::WriteLine( " {0}", st->GetFrame( 0 )->ToString() );
Console::WriteLine( " Line Number: {0}", st->GetFrame( 0 )->GetFileLineNumber().ToString() );
Console::WriteLine();
Console::WriteLine( " ... throwing exception to next level ..." );
Console::WriteLine( "-------------------------------------------------\n" );
throw e;
}
}
public void InternalMethod()
{
try
{
ClassLevel2 nestedClass = new ClassLevel2();
nestedClass.Level2Method();
}
catch (Exception e)
{
Console.WriteLine(" InternalMethod exception handler");
// Build a stack trace from one frame, skipping the
// current frame and using the next frame. By
// default, file and line information are not displayed.
StackTrace st = new StackTrace(new StackFrame(1));
Console.WriteLine(" Stack trace for next level frame: {0}",
st.ToString());
Console.WriteLine(" Stack frame for next level: ");
Console.WriteLine(" {0}", st.GetFrame(0).ToString());
Console.WriteLine(" Line Number: {0}",
st.GetFrame(0).GetFileLineNumber().ToString());
Console.WriteLine();
Console.WriteLine(" ... throwing exception to next level ...");
Console.WriteLine("-------------------------------------------------\n");
throw e;
}
}
Public Sub InternalMethod()
Try
Dim nestedClass As New ClassLevel2
nestedClass.Level2Method()
Catch e As Exception
Console.WriteLine(" InternalMethod exception handler")
' Build a stack trace from one frame, skipping the
' current frame and using the next frame. By default,
' file and line information are not displayed.
Dim st As New StackTrace(New StackFrame(1))
Console.WriteLine(" Stack trace for next level frame: {0}", _
st.ToString())
Console.WriteLine(" Stack frame for next level: ")
Console.WriteLine(" {0}", st.GetFrame(0).ToString())
Console.WriteLine(" Line Number: {0}", _
st.GetFrame(0).GetFileLineNumber().ToString())
Console.WriteLine()
Console.WriteLine(" ... throwing exception to next level ...")
Console.WriteLine("-------------------------------------------------")
Console.WriteLine()
Throw e
End Try
End Sub
S’applique à
Collaborer avec nous sur GitHub
La source de ce contenu se trouve sur GitHub, où vous pouvez également créer et examiner les problèmes et les demandes de tirage. Pour plus d’informations, consultez notre guide du contributeur.