StackTrace コンストラクター

定義

StackTrace クラスの新しいインスタンスを初期化します。

オーバーロード

StackTrace()

StackTrace クラスの新しいインスタンスを呼び出し元のフレームから初期化します。

StackTrace(Boolean)

StackTrace クラスの新しいインスタンスを呼び出し元のフレームから初期化し、オプションでソース情報をキャプチャします。

StackTrace(IEnumerable<StackFrame>)

オブジェクトのセット StackFrame からスタック トレースを構築します。

StackTrace(StackFrame)

単一フレームを格納している StackTrace クラスの新しいインスタンスを初期化します。

StackTrace(Exception)

指定した例外オブジェクトを使用して、StackTrace クラスの新しいインスタンスを初期化します。

StackTrace(Int32)

呼び出し元のフレームから StackTrace クラスの新しいインスタンスを初期化し、指定した数のフレームをスキップします。

StackTrace(Exception, Int32)

指定した例外オブジェクトを使用して StackTrace クラスの新しいインスタンスを初期化し、指定した数のフレームをスキップします。

StackTrace(Int32, Boolean)

呼び出し元のフレームから StackTrace クラスの新しいインスタンスを初期化し、指定した数のフレームをスキップしたり、必要に応じてソース情報を取得したりできます。

StackTrace(Thread, Boolean)
古い.

指定したスレッド用に StackTrace クラスの新しいインスタンスを初期化し、オプションでソース情報をキャプチャします。

このコンストラクター オーバーロードは使用しないでください。

StackTrace(Exception, Int32, Boolean)

指定した例外オブジェクトを使用して、StackTrace クラスの新しいインスタンスを初期化し、指定したフレーム数をスキップしたり、必要に応じてソース情報を取得したりできます。

StackTrace(Exception, Boolean)

指定した例外オブジェクトを使用して StackTrace クラスの新しいインスタンスを初期化し、オプションでソース情報をキャプチャします。

StackTrace()

StackTrace クラスの新しいインスタンスを呼び出し元のフレームから初期化します。

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

次のコード例では、スタック トレースの最初と最後の関数呼び出しを表示します。

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

注釈

StackTraceは呼び出し元の現在のスレッドで作成され、ファイル名、行番号、または列情報は含まれません。

呼び出し履歴に関する概要メソッド情報のみを含む完全なトレースが必要な場合は、このパラメーターなしのコンストラクターを使用します。

適用対象

StackTrace(Boolean)

StackTrace クラスの新しいインスタンスを呼び出し元のフレームから初期化し、オプションでソース情報をキャプチャします。

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

パラメーター

fNeedFileInfo
Boolean

ファイル名、行番号、および列番号をキャプチャする場合は true。それ以外の場合は false

次のコード例では、さまざまな StackTrace コンストラクター メソッドを示します。

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

注釈

StackTraceは、呼び出し元の現在のスレッドで作成されます。

適用対象

StackTrace(IEnumerable<StackFrame>)

オブジェクトのセット StackFrame からスタック トレースを構築します。

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

パラメーター

frames
IEnumerable<StackFrame>

スタック トレースに存在するスタック フレームのセット。

適用対象

StackTrace(StackFrame)

単一フレームを格納している StackTrace クラスの新しいインスタンスを初期化します。

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)

パラメーター

frame
StackFrame

StackTrace オブジェクトに格納するフレーム。

次のコード例では、スタック トレース情報をイベント ログ エントリに書き込みます。

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)

注釈

完全なスタック トレースのオーバーヘッドが不要な場合は、このコンストラクターを使用します。

こちらもご覧ください

適用対象

StackTrace(Exception)

指定した例外オブジェクトを使用して、StackTrace クラスの新しいインスタンスを初期化します。

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

パラメーター

e
Exception

スタック トレースを構築する基となる例外オブジェクト。

例外

e パラメーターが null です。

注釈

StackTraceは呼び出し元の現在のスレッドで作成され、ファイル名、行番号、または列情報は含まれません。

結果のスタック トレースでは、例外時にスタックが記述されます。

こちらもご覧ください

適用対象

StackTrace(Int32)

呼び出し元のフレームから StackTrace クラスの新しいインスタンスを初期化し、指定した数のフレームをスキップします。

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

パラメーター

skipFrames
Int32

トレースを開始するスタックまでのフレーム数。

例外

skipFrames パラメーターが負の値です。

注釈

StackTraceは呼び出し元の現在のスレッドで作成され、ファイル名、行番号、または列情報は含まれません。

スキップするフレーム数が、インスタンスの作成時に呼び出し履歴のフレームの合計数以上である場合、 StackTrace にはフレームは含まれます。

適用対象

StackTrace(Exception, Int32)

指定した例外オブジェクトを使用して StackTrace クラスの新しいインスタンスを初期化し、指定した数のフレームをスキップします。

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)

パラメーター

e
Exception

スタック トレースを構築する基となる例外オブジェクト。

skipFrames
Int32

トレースを開始するスタックまでのフレーム数。

例外

e パラメーターが null です。

skipFrames パラメーターが負の値です。

注釈

には StackTrace 、ファイル名、行番号、または列情報が含まれていません。

結果のスタック トレースでは、例外時にスタックが記述されます。

スキップするフレーム数が、インスタンスの作成時に呼び出し履歴のフレームの合計数以上である場合、 StackTrace にはフレームは含まれます。

こちらもご覧ください

適用対象

StackTrace(Int32, Boolean)

呼び出し元のフレームから StackTrace クラスの新しいインスタンスを初期化し、指定した数のフレームをスキップしたり、必要に応じてソース情報を取得したりできます。

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)

パラメーター

skipFrames
Int32

トレースを開始するスタックまでのフレーム数。

fNeedFileInfo
Boolean

ファイル名、行番号、および列番号をキャプチャする場合は true。それ以外の場合は false

例外

skipFrames パラメーターが負の値です。

次のコード例では、さまざまな StackTrace コンストラクター メソッドを示します。

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

注釈

スキップするフレーム数が、インスタンスの作成時に呼び出し履歴のフレームの合計数以上である場合、 StackTrace にはフレームは含まれます。

適用対象

StackTrace(Thread, Boolean)

注意事項

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

指定したスレッド用に StackTrace クラスの新しいインスタンスを初期化し、オプションでソース情報をキャプチャします。

このコンストラクター オーバーロードは使用しないでください。

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)

パラメーター

targetThread
Thread

スタック トレースを要求するスレッド。

needFileInfo
Boolean

ファイル名、行番号、および列番号をキャプチャする場合は true。それ以外の場合は false

属性

例外

スレッド targetThread が中断されていません。

注釈

重要

このコンストラクターは使用しないでください。 これは廃止されており、推奨される代替手段はありません。 スレッドを中断すると、どのコードが実行されているかを知る方法がなく、デッドロックが非常に簡単に発生する可能性があります。 たとえば、セキュリティアクセス許可の評価中にロックを保持している間にスレッドを中断すると、 内の他の AppDomain スレッドがブロックされる可能性があります。 クラス コンストラクターの実行中にスレッドを中断すると、そのクラスを使用しようとする 内の AppDomain 他のスレッドはブロックされます。

こちらもご覧ください

適用対象

StackTrace(Exception, Int32, Boolean)

指定した例外オブジェクトを使用して、StackTrace クラスの新しいインスタンスを初期化し、指定したフレーム数をスキップしたり、必要に応じてソース情報を取得したりできます。

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)

パラメーター

e
Exception

スタック トレースを構築する基となる例外オブジェクト。

skipFrames
Int32

トレースを開始するスタックまでのフレーム数。

fNeedFileInfo
Boolean

ファイル名、行番号、および列番号をキャプチャする場合は true。それ以外の場合は false

例外

e パラメーターが null です。

skipFrames パラメーターが負の値です。

注釈

結果のスタック トレースでは、例外時にスタックが記述されます。

スキップするフレーム数が、インスタンスの作成時に呼び出し履歴のフレームの合計数以上である場合、 StackTrace にはフレームは含まれます。

こちらもご覧ください

適用対象

StackTrace(Exception, Boolean)

指定した例外オブジェクトを使用して StackTrace クラスの新しいインスタンスを初期化し、オプションでソース情報をキャプチャします。

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)

パラメーター

exceptione
Exception

スタック トレースを構築する基となる例外オブジェクト。

needFileInfofNeedFileInfo
Boolean

ファイル名、行番号、および列番号をキャプチャする場合は true。それ以外の場合は false

例外

e パラメーターが null です。

注釈

結果のスタック トレースでは、例外時にスタックが記述されます。

こちらもご覧ください

適用対象