StackTrace Constructores

Definición

Inicializa una nueva instancia de la clase StackTrace.

Sobrecargas

StackTrace()

Inicializa una nueva instancia de la clase StackTrace a partir del marco del llamador.

StackTrace(Boolean)

Inicializa una nueva instancia de la clase StackTrace desde el marco del llamador y, opcionalmente, captura información de origen.

StackTrace(IEnumerable<StackFrame>)

Construye un seguimiento de pila a partir de un conjunto de StackFrame objetos.

StackTrace(StackFrame)

Inicializa una nueva instancia de la clase StackTrace que contiene un solo marco.

StackTrace(Exception)

Inicializa una nueva instancia de la clase StackTrace mediante el objeto de excepción proporcionado.

StackTrace(Int32)

Inicializa una nueva instancia de la clase StackTrace a partir del marco del llamador y pasa por alto el número de marcos especificado.

StackTrace(Exception, Int32)

Inicializa una nueva instancia de la clase StackTrace mediante el objeto de excepción proporcionado y pasa por alto el número de marcos especificado.

StackTrace(Int32, Boolean)

Inicializa una nueva instancia de la clase StackTrace a partir del marco del llamador, pasa por alto el número de marcos especificado y, opcionalmente, captura información de origen.

StackTrace(Thread, Boolean)
Obsoletos.

Inicializa una nueva instancia de la clase StackTrace para un subproceso específico y, opcionalmente, captura información de origen.

No utilice la sobrecarga de este constructor.

StackTrace(Exception, Int32, Boolean)

Inicializa una nueva instancia de la clase StackTrace mediante el objeto de excepción proporcionado, pasa por alto el número de marcos especificado y, opcionalmente, captura información de origen.

StackTrace(Exception, Boolean)

Inicializa una nueva instancia de la clase StackTrace mediante el objeto de excepción que se suministra y, opcionalmente, captura información de origen.

StackTrace()

Inicializa una nueva instancia de la clase StackTrace a partir del marco del llamador.

public:
 StackTrace();
public StackTrace ();
Public Sub New ()

Ejemplos

En el ejemplo de código siguiente se muestran las llamadas de primera y última función en un seguimiento de pila.

void Level5Method()
{
   try
   {
      ClassLevel6^ nestedClass = gcnew ClassLevel6;
      nestedClass->Level6Method();
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( " Level5Method exception handler" );
      StackTrace^ st = gcnew StackTrace;
      
      // Display the most recent function call.
      StackFrame^ sf = st->GetFrame( 0 );
      Console::WriteLine();
      Console::WriteLine( "  Exception in method: " );
      Console::WriteLine( "      {0}", sf->GetMethod() );
      if ( st->FrameCount > 1 )
      {
         
         // Display the highest-level function call
         // in the trace.
         sf = st->GetFrame( st->FrameCount - 1 );
         Console::WriteLine( "  Original function call at top of call stack):" );
         Console::WriteLine( "      {0}", sf->GetMethod() );
      }
      Console::WriteLine();
      Console::WriteLine( "   ... throwing exception to next level ..." );
      Console::WriteLine( "-------------------------------------------------\n" );
      throw e;
   }

}
public void Level5Method()
{
   try
   {
      ClassLevel6 nestedClass = new ClassLevel6();
      nestedClass.Level6Method();
   }
   catch (Exception e)
   {
      Console.WriteLine(" Level5Method exception handler");

      StackTrace st = new StackTrace();

      // Display the most recent function call.
      StackFrame sf = st.GetFrame(0);
      Console.WriteLine();
      Console.WriteLine("  Exception in method: ");
      Console.WriteLine("      {0}", sf.GetMethod());

      if (st.FrameCount >1)
      {
         // Display the highest-level function call
         // in the trace.
         sf = st.GetFrame(st.FrameCount-1);
         Console.WriteLine("  Original function call at top of call stack):");
         Console.WriteLine("      {0}", sf.GetMethod());
      }

      Console.WriteLine();
      Console.WriteLine("   ... throwing exception to next level ...");
      Console.WriteLine("-------------------------------------------------\n");
      throw e;
   }
}
Public Sub Level5Method()
   Try
      Dim nestedClass As New ClassLevel6()
      nestedClass.Level6Method()
   Catch e As Exception
      Console.WriteLine(" Level5Method exception handler")
      
      Dim st As New StackTrace()
      
      ' Display the most recent function call.
      Dim sf As StackFrame = st.GetFrame(0)
      Console.WriteLine()
      Console.WriteLine("  Exception in method: ")
      Console.WriteLine("      {0}", sf.GetMethod())
      
      If st.FrameCount > 1 Then
         ' Display the highest-level function call in the trace.
         sf = st.GetFrame((st.FrameCount - 1))
         Console.WriteLine("  Original function call at top of call stack):")
         Console.WriteLine("      {0}", sf.GetMethod())
      End If
      
      Console.WriteLine()
      Console.WriteLine("   ... throwing exception to next level ...")
      Console.WriteLine("-------------------------------------------------")
      Console.WriteLine()
      Throw e
   End Try
End Sub

Comentarios

StackTrace se crea con el subproceso actual del autor de la llamada y no contiene información de nombre de archivo, número de línea o columna.

Use este constructor sin parámetros cuando desee un seguimiento completo con solo información de método de resumen sobre la pila de llamadas.

Se aplica a

StackTrace(Boolean)

Inicializa una nueva instancia de la clase StackTrace desde el marco del llamador y, opcionalmente, captura información de origen.

public:
 StackTrace(bool fNeedFileInfo);
public StackTrace (bool fNeedFileInfo);
new System.Diagnostics.StackTrace : bool -> System.Diagnostics.StackTrace
Public Sub New (fNeedFileInfo As Boolean)

Parámetros

fNeedFileInfo
Boolean

Es true para capturar el nombre de archivo y los números de línea y de columna; en caso contrario, es false.

Ejemplos

En el ejemplo de código siguiente se muestran varios StackTrace métodos de constructor.

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()
{
   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;
   }
}
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

Comentarios

StackTrace se crea con el subproceso actual del autor de la llamada.

Se aplica a

StackTrace(IEnumerable<StackFrame>)

Construye un seguimiento de pila a partir de un conjunto de StackFrame objetos.

public:
 StackTrace(System::Collections::Generic::IEnumerable<System::Diagnostics::StackFrame ^> ^ frames);
public StackTrace (System.Collections.Generic.IEnumerable<System.Diagnostics.StackFrame> frames);
new System.Diagnostics.StackTrace : seq<System.Diagnostics.StackFrame> -> System.Diagnostics.StackTrace
Public Sub New (frames As IEnumerable(Of StackFrame))

Parámetros

frames
IEnumerable<StackFrame>

Conjunto de marcos de pila que deben estar presentes en el seguimiento de la pila.

Se aplica a

StackTrace(StackFrame)

Inicializa una nueva instancia de la clase StackTrace que contiene un solo marco.

public:
 StackTrace(System::Diagnostics::StackFrame ^ frame);
public StackTrace (System.Diagnostics.StackFrame frame);
new System.Diagnostics.StackTrace : System.Diagnostics.StackFrame -> System.Diagnostics.StackTrace
Public Sub New (frame As StackFrame)

Parámetros

frame
StackFrame

Marco que el objeto StackTrace debe contener.

Ejemplos

En el ejemplo de código siguiente se escribe información de seguimiento de pila en una entrada de registro de eventos.

StackFrame^ fr = gcnew StackFrame( 1,true );
StackTrace^ st = gcnew StackTrace( fr );
EventLog::WriteEntry( fr->GetMethod()->Name, st->ToString(), EventLogEntryType::Warning );
StackFrame fr = new StackFrame(1,true);
StackTrace st = new StackTrace(fr);
EventLog.WriteEntry(fr.GetMethod().Name,
                    st.ToString(),
                    EventLogEntryType.Warning);
Dim frame As New StackFrame(1, True)
Dim strace As New StackTrace(frame)            

EventLog.WriteEntry(frame.GetMethod().Name, _
                    strace.ToString(), _
                    EventLogEntryType.Warning)

Comentarios

Use este constructor cuando no desee la sobrecarga de un seguimiento de pila completo.

Consulte también

Se aplica a

StackTrace(Exception)

Inicializa una nueva instancia de la clase StackTrace mediante el objeto de excepción proporcionado.

public:
 StackTrace(Exception ^ e);
public StackTrace (Exception e);
new System.Diagnostics.StackTrace : Exception -> System.Diagnostics.StackTrace
Public Sub New (e As Exception)

Parámetros

e
Exception

Objeto de excepción a partir del que se va a generar el seguimiento de la pila.

Excepciones

El parámetro e es null.

Comentarios

StackTrace se crea con el subproceso actual del autor de la llamada y no contiene información de nombre de archivo, número de línea o columna.

El seguimiento de pila resultante describe la pila en el momento de la excepción.

Consulte también

Se aplica a

StackTrace(Int32)

Inicializa una nueva instancia de la clase StackTrace a partir del marco del llamador y pasa por alto el número de marcos especificado.

public:
 StackTrace(int skipFrames);
public StackTrace (int skipFrames);
new System.Diagnostics.StackTrace : int -> System.Diagnostics.StackTrace
Public Sub New (skipFrames As Integer)

Parámetros

skipFrames
Int32

Número de marcos que debe contener la pila para iniciar el seguimiento.

Excepciones

El parámetro skipFrames es negativo.

Comentarios

StackTrace se crea con el subproceso actual del autor de la llamada y no contiene información de nombre de archivo, número de línea o columna.

Si el número de fotogramas que se omitirán es mayor o igual que el número total de fotogramas de la pila de llamadas en el momento en que se crea la instancia, no StackTrace contendrá ningún fotograma.

Se aplica a

StackTrace(Exception, Int32)

Inicializa una nueva instancia de la clase StackTrace mediante el objeto de excepción proporcionado y pasa por alto el número de marcos especificado.

public:
 StackTrace(Exception ^ e, int skipFrames);
public StackTrace (Exception e, int skipFrames);
new System.Diagnostics.StackTrace : Exception * int -> System.Diagnostics.StackTrace
Public Sub New (e As Exception, skipFrames As Integer)

Parámetros

e
Exception

Objeto de excepción a partir del que se va a generar el seguimiento de la pila.

skipFrames
Int32

Número de marcos que debe contener la pila para iniciar el seguimiento.

Excepciones

El parámetro e es null.

El parámetro skipFrames es negativo.

Comentarios

StackTrace no contiene información de nombre de archivo, número de línea ni columna.

El seguimiento de pila resultante describe la pila en el momento de la excepción.

Si el número de fotogramas que se omitirán es mayor o igual que el número total de fotogramas de la pila de llamadas en el momento en que se crea la instancia, no StackTrace contendrá ningún fotograma.

Consulte también

Se aplica a

StackTrace(Int32, Boolean)

Inicializa una nueva instancia de la clase StackTrace a partir del marco del llamador, pasa por alto el número de marcos especificado y, opcionalmente, captura información de origen.

public:
 StackTrace(int skipFrames, bool fNeedFileInfo);
public StackTrace (int skipFrames, bool fNeedFileInfo);
new System.Diagnostics.StackTrace : int * bool -> System.Diagnostics.StackTrace
Public Sub New (skipFrames As Integer, fNeedFileInfo As Boolean)

Parámetros

skipFrames
Int32

Número de marcos que debe contener la pila para iniciar el seguimiento.

fNeedFileInfo
Boolean

Es true para capturar el nombre de archivo y los números de línea y de columna; en caso contrario, es false.

Excepciones

El parámetro skipFrames es negativo.

Ejemplos

En el ejemplo de código siguiente se muestran varios StackTrace métodos de constructor.

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()
{
   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;
   }
}
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

Comentarios

Si el número de fotogramas que se omitirán es mayor o igual que el número total de fotogramas de la pila de llamadas en el momento en que se crea la instancia, no StackTrace contendrá ningún fotograma.

Se aplica a

StackTrace(Thread, Boolean)

Precaución

This constructor has been deprecated. Please use a constructor that does not require a Thread parameter. http://go.microsoft.com/fwlink/?linkid=14202

Inicializa una nueva instancia de la clase StackTrace para un subproceso específico y, opcionalmente, captura información de origen.

No utilice la sobrecarga de este constructor.

public:
 StackTrace(System::Threading::Thread ^ targetThread, bool needFileInfo);
public StackTrace (System.Threading.Thread targetThread, bool needFileInfo);
[System.Obsolete("This constructor has been deprecated.  Please use a constructor that does not require a Thread parameter.  http://go.microsoft.com/fwlink/?linkid=14202")]
public StackTrace (System.Threading.Thread targetThread, bool needFileInfo);
new System.Diagnostics.StackTrace : System.Threading.Thread * bool -> System.Diagnostics.StackTrace
[<System.Obsolete("This constructor has been deprecated.  Please use a constructor that does not require a Thread parameter.  http://go.microsoft.com/fwlink/?linkid=14202")>]
new System.Diagnostics.StackTrace : System.Threading.Thread * bool -> System.Diagnostics.StackTrace
Public Sub New (targetThread As Thread, needFileInfo As Boolean)

Parámetros

targetThread
Thread

Subproceso cuyo seguimiento de pila se solicita.

needFileInfo
Boolean

Es true para capturar el nombre de archivo y los números de línea y de columna; en caso contrario, es false.

Atributos

Excepciones

El subproceso targetThread no se suspende.

Comentarios

Importante

No utilice este constructor. Está obsoleto y no hay ninguna alternativa recomendada. Cuando suspende un subproceso, no tiene forma de saber qué código se está ejecutando y los interbloqueos pueden producirse muy fácilmente. Por ejemplo, si suspende un subproceso mientras contiene bloqueos durante una evaluación de permisos de seguridad, es posible que se bloqueen otros subprocesos de .AppDomain Si suspende un subproceso mientras ejecuta un constructor de clase, se bloquean otros subprocesos del AppDomain objeto que intentan usar esa clase.

Consulte también

Se aplica a

StackTrace(Exception, Int32, Boolean)

Inicializa una nueva instancia de la clase StackTrace mediante el objeto de excepción proporcionado, pasa por alto el número de marcos especificado y, opcionalmente, captura información de origen.

public:
 StackTrace(Exception ^ e, int skipFrames, bool fNeedFileInfo);
public StackTrace (Exception e, int skipFrames, bool fNeedFileInfo);
new System.Diagnostics.StackTrace : Exception * int * bool -> System.Diagnostics.StackTrace
Public Sub New (e As Exception, skipFrames As Integer, fNeedFileInfo As Boolean)

Parámetros

e
Exception

Objeto de excepción a partir del que se va a generar el seguimiento de la pila.

skipFrames
Int32

Número de marcos que debe contener la pila para iniciar el seguimiento.

fNeedFileInfo
Boolean

Es true para capturar el nombre de archivo y los números de línea y de columna; en caso contrario, es false.

Excepciones

El parámetro e es null.

El parámetro skipFrames es negativo.

Comentarios

El seguimiento de pila resultante describe la pila en el momento de la excepción.

Si el número de fotogramas que se omitirán es mayor o igual que el número total de fotogramas de la pila de llamadas en el momento en que se crea la instancia, no StackTrace contendrá ningún fotograma.

Consulte también

Se aplica a

StackTrace(Exception, Boolean)

Inicializa una nueva instancia de la clase StackTrace mediante el objeto de excepción que se suministra y, opcionalmente, captura información de origen.

public:
 StackTrace(Exception ^ exception, bool needFileInfo);
public:
 StackTrace(Exception ^ e, bool fNeedFileInfo);
public StackTrace (Exception exception, bool needFileInfo);
public StackTrace (Exception e, bool fNeedFileInfo);
new System.Diagnostics.StackTrace : Exception * bool -> System.Diagnostics.StackTrace
new System.Diagnostics.StackTrace : Exception * bool -> System.Diagnostics.StackTrace
Public Sub New (exception As Exception, needFileInfo As Boolean)
Public Sub New (e As Exception, fNeedFileInfo As Boolean)

Parámetros

exceptione
Exception

Objeto de excepción a partir del que se va a generar el seguimiento de la pila.

needFileInfofNeedFileInfo
Boolean

Es true para capturar el nombre de archivo y los números de línea y de columna; en caso contrario, es false.

Excepciones

El parámetro e es null.

Comentarios

El seguimiento de pila resultante describe la pila en el momento de la excepción.

Consulte también

Se aplica a