次の方法で共有


StackTrace コンストラクタ (Boolean)

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

名前空間: System.Diagnostics
アセンブリ: mscorlib (mscorlib.dll 内)

構文

'宣言
Public Sub New ( _
    fNeedFileInfo As Boolean _
)
'使用
Dim fNeedFileInfo As Boolean

Dim instance As New StackTrace(fNeedFileInfo)
public StackTrace (
    bool fNeedFileInfo
)
public:
StackTrace (
    bool fNeedFileInfo
)
public StackTrace (
    boolean fNeedFileInfo
)
public function StackTrace (
    fNeedFileInfo : boolean
)

パラメータ

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

解説

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

使用例

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

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 'Level2Method
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;
   }
}
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() throws System.Exception
{
    try {
        ClassLevel3 nestedClass = new ClassLevel3();
        nestedClass.Level3Method();
    }
    catch (System.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;
    }
} //Level2Method

プラットフォーム

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

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

参照

関連項目

StackTrace クラス
StackTrace メンバ
System.Diagnostics 名前空間