Exportar (0) Imprimir
Expandir todo

StackFrame.ToString (Método)

Crea una representación legible del seguimiento de pila.

Espacio de nombres: System.Diagnostics
Ensamblado: mscorlib (en mscorlib.dll)

public override string ToString ()
public String ToString ()
public override function ToString () : String

Valor devuelto

Devuelve una representación legible.

En el siguiente ejemplo de código se muestra la forma de utilizar el método ToString.

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 void InternalMethod() throws System.Exception
{
    try {
        ClassLevel2 nestedClass = new ClassLevel2();
        nestedClass.Level2Method();
    }
    catch (System.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}", 
            Convert.ToString(st.GetFrame(0).GetFileLineNumber()));
        Console.WriteLine();
        Console.WriteLine(" ... throwing exception to next level...");
        Console.WriteLine("-------------------------------------------"
            + "------\n");
        throw e;
    }
} //InternalMethod

Windows 98, Windows 2000 SP4, Windows Millennium, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter Edition

.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.

.NET Framework

Compatible con: 2.0, 1.1, 1.0

Adiciones de comunidad

AGREGAR
Mostrar:
© 2014 Microsoft