StackTrace Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy StackTrace.

Przeciążenia

StackTrace()

Inicjuje StackTrace nowe wystąpienie klasy z ramki obiektu wywołującego.

StackTrace(Boolean)

Inicjuje nowe wystąpienie StackTrace klasy z ramki obiektu wywołującego, opcjonalnie przechwytując informacje źródłowe.

StackTrace(IEnumerable<StackFrame>)

Tworzy ślad stosu StackFrame z zestawu obiektów.

StackTrace(StackFrame)

Inicjuje StackTrace nowe wystąpienie klasy zawierającej jedną ramkę.

StackTrace(Exception)

Inicjuje StackTrace nowe wystąpienie klasy przy użyciu podanego obiektu wyjątku.

StackTrace(Int32)

Inicjuje nowe wystąpienie StackTrace klasy z ramki obiektu wywołującego, pomijając określoną liczbę ramek.

StackTrace(Exception, Int32)

Inicjuje StackTrace nowe wystąpienie klasy przy użyciu dostarczonego obiektu wyjątku i pomija określoną liczbę ramek.

StackTrace(Int32, Boolean)

Inicjuje nowe wystąpienie StackTrace klasy z ramki obiektu wywołującego, pomijając określoną liczbę ramek i opcjonalnie przechwytując informacje źródłowe.

StackTrace(Thread, Boolean)
Przestarzałe.

Inicjuje nowe wystąpienie klasy dla określonego StackTrace wątku, opcjonalnie przechwytując informacje źródłowe.

Nie używaj tego przeciążenia konstruktora.

StackTrace(Exception, Int32, Boolean)

Inicjuje nowe wystąpienie StackTrace klasy przy użyciu dostarczonego obiektu wyjątku, pomijając określoną liczbę ramek i opcjonalnie przechwytując informacje źródłowe.

StackTrace(Exception, Boolean)

Inicjuje nowe wystąpienie klasy przy użyciu podanego obiektu wyjątku StackTrace i opcjonalnie przechwytuje informacje źródłowe.

StackTrace()

Źródło:
StackTrace.cs
Źródło:
StackTrace.cs
Źródło:
StackTrace.cs

Inicjuje StackTrace nowe wystąpienie klasy z ramki obiektu wywołującego.

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

Przykłady

Poniższy przykład kodu przedstawia pierwsze i ostatnie wywołania funkcji w śladzie stosu.

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

Uwagi

Obiekt StackTrace jest tworzony przy użyciu bieżącego wątku wywołującego i nie zawiera nazwy pliku, numeru wiersza ani informacji o kolumnie.

Użyj tego konstruktora bez parametrów, jeśli chcesz, aby pełny ślad zawierał tylko informacje o metodzie podsumowania dotyczące stosu wywołań.

Dotyczy

StackTrace(Boolean)

Źródło:
StackTrace.cs
Źródło:
StackTrace.cs
Źródło:
StackTrace.cs

Inicjuje nowe wystąpienie StackTrace klasy z ramki obiektu wywołującego, opcjonalnie przechwytując informacje źródłowe.

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

Parametry

fNeedFileInfo
Boolean

true aby przechwycić nazwę pliku, numer wiersza i numer kolumny; w przeciwnym razie , false.

Przykłady

W poniższym przykładzie kodu przedstawiono różne StackTrace metody konstruktora.

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

Uwagi

Element StackTrace jest tworzony przy użyciu bieżącego wątku elementu wywołującego.

Dotyczy

StackTrace(IEnumerable<StackFrame>)

Źródło:
StackTrace.cs
Źródło:
StackTrace.cs

Tworzy ślad stosu StackFrame z zestawu obiektów.

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))

Parametry

frames
IEnumerable<StackFrame>

Zestaw ramek stosu, które powinny być obecne w śladzie stosu.

Dotyczy

StackTrace(StackFrame)

Źródło:
StackTrace.cs
Źródło:
StackTrace.cs
Źródło:
StackTrace.cs

Inicjuje StackTrace nowe wystąpienie klasy zawierającej jedną ramkę.

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)

Parametry

frame
StackFrame

Ramka, którą StackTrace powinien zawierać obiekt.

Przykłady

Poniższy przykład kodu zapisuje informacje śledzenia stosu do wpisu dziennika zdarzeń.

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)

Uwagi

Użyj tego konstruktora, gdy nie chcesz przerzucać całego śladu stosu.

Zobacz też

Dotyczy

StackTrace(Exception)

Źródło:
StackTrace.cs
Źródło:
StackTrace.cs
Źródło:
StackTrace.cs

Inicjuje StackTrace nowe wystąpienie klasy przy użyciu podanego obiektu wyjątku.

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

Parametry

e
Exception

Obiekt wyjątku, z którego ma być skonstruowany ślad stosu.

Wyjątki

Parametr e to null.

Uwagi

Obiekt StackTrace jest tworzony przy użyciu bieżącego wątku wywołującego i nie zawiera nazwy pliku, numeru wiersza ani informacji o kolumnie.

Wynikowy ślad stosu opisuje stos w momencie wystąpienia wyjątku.

Zobacz też

Dotyczy

StackTrace(Int32)

Źródło:
StackTrace.cs
Źródło:
StackTrace.cs
Źródło:
StackTrace.cs

Inicjuje nowe wystąpienie StackTrace klasy z ramki obiektu wywołującego, pomijając określoną liczbę ramek.

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

Parametry

skipFrames
Int32

Liczba ramek w górę stosu, z którego ma rozpocząć śledzenie.

Wyjątki

Parametr jest ujemny skipFrames .

Uwagi

Obiekt StackTrace jest tworzony przy użyciu bieżącego wątku wywołującego i nie zawiera nazwy pliku, numeru wiersza ani informacji o kolumnie.

Jeśli liczba ramek do pominięcia jest większa lub równa całkowitej liczbie ramek w stosie wywołań w momencie utworzenia wystąpienia, element StackTrace nie będzie zawierać ramek.

Dotyczy

StackTrace(Exception, Int32)

Źródło:
StackTrace.cs
Źródło:
StackTrace.cs
Źródło:
StackTrace.cs

Inicjuje StackTrace nowe wystąpienie klasy przy użyciu dostarczonego obiektu wyjątku i pomija określoną liczbę ramek.

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)

Parametry

e
Exception

Obiekt wyjątku, z którego ma być skonstruowany ślad stosu.

skipFrames
Int32

Liczba ramek w górę stosu, z którego ma rozpocząć śledzenie.

Wyjątki

Parametr e to null.

Parametr jest ujemny skipFrames .

Uwagi

Element StackTrace nie zawiera nazwy pliku, numeru wiersza ani informacji o kolumnie.

Wynikowy ślad stosu opisuje stos w momencie wystąpienia wyjątku.

Jeśli liczba ramek do pominięcia jest większa lub równa całkowitej liczbie ramek w stosie wywołań w momencie utworzenia wystąpienia, element StackTrace nie będzie zawierać ramek.

Zobacz też

Dotyczy

StackTrace(Int32, Boolean)

Źródło:
StackTrace.cs
Źródło:
StackTrace.cs
Źródło:
StackTrace.cs

Inicjuje nowe wystąpienie StackTrace klasy z ramki obiektu wywołującego, pomijając określoną liczbę ramek i opcjonalnie przechwytując informacje źródłowe.

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)

Parametry

skipFrames
Int32

Liczba ramek w górę stosu, z którego ma rozpocząć śledzenie.

fNeedFileInfo
Boolean

true aby przechwycić nazwę pliku, numer wiersza i numer kolumny; w przeciwnym razie , false.

Wyjątki

Parametr jest ujemny skipFrames .

Przykłady

W poniższym przykładzie kodu przedstawiono różne StackTrace metody konstruktora.

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

Uwagi

Jeśli liczba ramek do pominięcia jest większa lub równa całkowitej liczbie ramek w stosie wywołań w momencie utworzenia wystąpienia, element StackTrace nie będzie zawierać ramek.

Dotyczy

StackTrace(Thread, Boolean)

Przestroga

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

Inicjuje nowe wystąpienie klasy dla określonego StackTrace wątku, opcjonalnie przechwytując informacje źródłowe.

Nie używaj tego przeciążenia konstruktora.

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)

Parametry

targetThread
Thread

Wątek, którego żądanie śledzenia stosu jest wymagane.

needFileInfo
Boolean

true aby przechwycić nazwę pliku, numer wiersza i numer kolumny; w przeciwnym razie , false.

Atrybuty

Wyjątki

Wątek targetThread nie jest zawieszony.

Uwagi

Ważne

Nie używaj tego konstruktora. Jest przestarzałe i nie ma zalecanej alternatywy. W przypadku zawieszenia wątku nie wiesz, jaki kod wykonuje, a zakleszczenia mogą wystąpić bardzo łatwo. Jeśli na przykład zawieszasz wątek, gdy przechowuje blokady podczas oceny uprawnień zabezpieczeń, inne wątki w obiekcie AppDomain mogą zostać zablokowane. Jeśli zawiesisz wątek podczas wykonywania konstruktora klasy, inne wątki w AppDomain tej próbie użycia tej klasy są zablokowane.

Zobacz też

Dotyczy

StackTrace(Exception, Int32, Boolean)

Źródło:
StackTrace.cs
Źródło:
StackTrace.cs
Źródło:
StackTrace.cs

Inicjuje nowe wystąpienie StackTrace klasy przy użyciu dostarczonego obiektu wyjątku, pomijając określoną liczbę ramek i opcjonalnie przechwytując informacje źródłowe.

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)

Parametry

e
Exception

Obiekt wyjątku, z którego ma być skonstruowany ślad stosu.

skipFrames
Int32

Liczba ramek w górę stosu, z którego ma rozpocząć śledzenie.

fNeedFileInfo
Boolean

true aby przechwycić nazwę pliku, numer wiersza i numer kolumny; w przeciwnym razie , false.

Wyjątki

Parametr e to null.

Parametr jest ujemny skipFrames .

Uwagi

Wynikowy ślad stosu opisuje stos w momencie wystąpienia wyjątku.

Jeśli liczba ramek do pominięcia jest większa lub równa całkowitej liczbie ramek w stosie wywołań w momencie utworzenia wystąpienia, element StackTrace nie będzie zawierać ramek.

Zobacz też

Dotyczy

StackTrace(Exception, Boolean)

Źródło:
StackTrace.cs
Źródło:
StackTrace.cs
Źródło:
StackTrace.cs

Inicjuje nowe wystąpienie klasy przy użyciu podanego obiektu wyjątku StackTrace i opcjonalnie przechwytuje informacje źródłowe.

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)

Parametry

exceptione
Exception

Obiekt wyjątku, z którego ma być skonstruowany ślad stosu.

needFileInfofNeedFileInfo
Boolean

true aby przechwycić nazwę pliku, numer wiersza i numer kolumny; w przeciwnym razie , false.

Wyjątki

Parametr e to null.

Uwagi

Wynikowy ślad stosu opisuje stos w momencie wystąpienia wyjątku.

Zobacz też

Dotyczy