StackFrame.ToString Metodo

Definizione

Compila una rappresentazione leggibile dell'analisi dello stack.

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

Restituisce

Rappresentazione leggibile dell'analisi dello stack.

Esempio

Nell'esempio seguente viene illustrato l'uso del metodo ToString. Questo esempio di codice fa parte di un esempio più grande fornito per 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

Si applica a