StackFrame StackFrame StackFrame StackFrame Constructors

定義

オーバーロード

StackFrame() StackFrame() StackFrame()

StackFrame クラスの新しいインスタンスを初期化します。Initializes a new instance of the StackFrame class.

StackFrame(Boolean) StackFrame(Boolean) StackFrame(Boolean) StackFrame(Boolean)

StackFrame クラスの新しいインスタンスを初期化し、オプションでソース情報をキャプチャします。Initializes a new instance of the StackFrame class, optionally capturing source information.

StackFrame(Int32) StackFrame(Int32) StackFrame(Int32) StackFrame(Int32)

現在のスタック フレーム上のフレームに対応する StackFrame クラスの新しいインスタンスを初期化します。Initializes a new instance of the StackFrame class that corresponds to a frame above the current stack frame.

StackFrame(Int32, Boolean) StackFrame(Int32, Boolean) StackFrame(Int32, Boolean) StackFrame(Int32, Boolean)

現在のスタック フレーム上のフレームに対応する StackFrame クラスの新しいインスタンスを初期化し、オプションでソース情報をキャプチャします。Initializes a new instance of the StackFrame class that corresponds to a frame above the current stack frame, optionally capturing source information.

StackFrame(String, Int32) StackFrame(String, Int32) StackFrame(String, Int32) StackFrame(String, Int32)

指定されたファイル名および行番号だけを含む StackFrame クラスの新しいインスタンスを初期化します。Initializes a new instance of the StackFrame class that contains only the given file name and line number.

StackFrame(String, Int32, Int32) StackFrame(String, Int32, Int32) StackFrame(String, Int32, Int32) StackFrame(String, Int32, Int32)

指定されたファイル名、行番号、および列番号だけを含む StackFrame クラスの新しいインスタンスを初期化します。Initializes a new instance of the StackFrame class that contains only the given file name, line number, and column number.

StackFrame() StackFrame() StackFrame()

StackFrame クラスの新しいインスタンスを初期化します。Initializes a new instance of the StackFrame class.

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

StackFrame(Boolean) StackFrame(Boolean) StackFrame(Boolean) StackFrame(Boolean)

StackFrame クラスの新しいインスタンスを初期化し、オプションでソース情報をキャプチャします。Initializes a new instance of the StackFrame class, optionally capturing source information.

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

パラメーター

fNeedFileInfo
Boolean Boolean Boolean Boolean

スタック フレームのファイル名、行番号、および列番号をキャプチャする場合は true。それ以外の場合は falsetrue to capture the file name, line number, and column number of the stack frame; otherwise, false.

次の例では、使用、StackFrame(Boolean)コンス トラクター。The following example demonstrates the use of the StackFrame(Boolean) constructor. このコード例が示されている例の一部、StackFrameクラス。This code example is part of a larger example provided for the StackFrame class.


[STAThread]
static void Main()
{
   ClassLevel1 ^ mainClass = gcnew ClassLevel1;
   try
   {
      mainClass->InternalMethod();
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( " Main method exception handler" );
      
      // Display file and line information, if available.
      StackTrace^ st = gcnew StackTrace( gcnew StackFrame( true ) );
      Console::WriteLine( " Stack trace for current level: {0}", st->ToString() );
      Console::WriteLine( " File: {0}", st->GetFrame( 0 )->GetFileName() );
      Console::WriteLine( " Line Number: {0}", st->GetFrame( 0 )->GetFileLineNumber().ToString() );
      Console::WriteLine();
      Console::WriteLine( "-------------------------------------------------\n" );
   }

}

[STAThread]
static void Main()
 {
     ClassLevel1 mainClass = new ClassLevel1();

     try {
         mainClass.InternalMethod();
     }
     catch (Exception) {
        Console.WriteLine(" Main method exception handler");

        // Display file and line information, if available.
        StackTrace st = new StackTrace(new StackFrame(true));
        Console.WriteLine(" Stack trace for current level: {0}",
            st.ToString());
        Console.WriteLine(" File: {0}", 
           st.GetFrame(0).GetFileName());
        Console.WriteLine(" Line Number: {0}",
            st.GetFrame(0).GetFileLineNumber().ToString());

        Console.WriteLine();
        Console.WriteLine("-------------------------------------------------\n");
     }
 }
<STAThread()>  _
Shared Sub Main()
   Dim mainClass As New ClassLevel1
   
   Try
      mainClass.InternalMethod()
   Catch
      Console.WriteLine(" Main method exception handler")
      
      ' Display file and line information, if available.
      Dim st As New StackTrace(New StackFrame(True))
      Console.WriteLine(" Stack trace for current level: {0}", _
         st.ToString())
      Console.WriteLine(" File: {0}", _
         st.GetFrame(0).GetFileName())
      Console.WriteLine(" Line Number: {0}", _
         st.GetFrame(0).GetFileLineNumber().ToString())
      
      Console.WriteLine()
      Console.WriteLine("-------------------------------------------------")
      Console.WriteLine()
   End Try
End Sub 'Main

StackFrame(Int32) StackFrame(Int32) StackFrame(Int32) StackFrame(Int32)

現在のスタック フレーム上のフレームに対応する StackFrame クラスの新しいインスタンスを初期化します。Initializes a new instance of the StackFrame class that corresponds to a frame above the current stack frame.

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

パラメーター

skipFrames
Int32 Int32 Int32 Int32

スキップするスタック上のフレーム数。The number of frames up the stack to skip.

次の例では、使用、StackFrame(Int32)コンス トラクター。The following example demonstrates the use of the StackFrame(Int32) constructor. このコード例が示されている例の一部、StackFrameクラス。This code example is part of a larger example provided for the StackFrame class.

void InternalMethod()
{
   try
   {
      ClassLevel2^ nestedClass = gcnew 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 = gcnew StackTrace( gcnew 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()
{
   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 Sub InternalMethod()
   Try
      Dim nestedClass As New ClassLevel2
      nestedClass.Level2Method()
   Catch e As Exception
      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.
      Dim st As 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("-------------------------------------------------")
      Console.WriteLine()
      Throw e
   End Try
End Sub 'InternalMethod

StackFrame(Int32, Boolean) StackFrame(Int32, Boolean) StackFrame(Int32, Boolean) StackFrame(Int32, Boolean)

現在のスタック フレーム上のフレームに対応する StackFrame クラスの新しいインスタンスを初期化し、オプションでソース情報をキャプチャします。Initializes a new instance of the StackFrame class that corresponds to a frame above the current stack frame, optionally capturing source information.

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

パラメーター

skipFrames
Int32 Int32 Int32 Int32

スキップするスタック上のフレーム数。The number of frames up the stack to skip.

fNeedFileInfo
Boolean Boolean Boolean Boolean

スタック フレームのファイル名、行番号、および列番号をキャプチャする場合は true。それ以外の場合は falsetrue to capture the file name, line number, and column number of the stack frame; otherwise, false.

次の例では、使用、StackFrame(Int32, Boolean)コンス トラクター。The following example demonstrates the use of the StackFrame(Int32, Boolean) constructor. このコード例が示されている例の一部、StackFrameクラス。This code example is part of a larger example provided for the StackFrame class.

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 'Level2Method

StackFrame(String, Int32) StackFrame(String, Int32) StackFrame(String, Int32) StackFrame(String, Int32)

指定されたファイル名および行番号だけを含む StackFrame クラスの新しいインスタンスを初期化します。Initializes a new instance of the StackFrame class that contains only the given file name and line number.

public:
 StackFrame(System::String ^ fileName, int lineNumber);
public StackFrame (string fileName, int lineNumber);
new System.Diagnostics.StackFrame : string * int -> System.Diagnostics.StackFrame
Public Sub New (fileName As String, lineNumber As Integer)

パラメーター

fileName
String String String String

ファイル名。The file name.

lineNumber
Int32 Int32 Int32 Int32

指定したファイルの行番号。The line number in the specified file.

次の例では、使用、StackFrame(String, Int32)コンス トラクター。The following example demonstrates the use of the StackFrame(String, Int32) constructor. このコード例が示されている例の一部、StackFrameクラス。This code example is part of a larger example provided for the StackFrame class.

void Level3Method()
{
   try
   {
      ClassLevel4^ nestedClass = gcnew ClassLevel4;
      nestedClass->Level4Method();
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( " Level3Method exception handler" );
      
      // Build a stack trace from a dummy stack frame.
      // Explicitly specify the source file name and line number.
      StackTrace^ st = gcnew StackTrace( gcnew StackFrame( "source.cs",60 ) );
      Console::WriteLine( " Stack trace with dummy stack frame: {0}", st->ToString() );
      for ( int i = 0; i < st->FrameCount; i++ )
      {
         
         // Display the stack frame properties.
         StackFrame^ sf = st->GetFrame( i );
         Console::WriteLine( " File: {0}", sf->GetFileName() );
         Console::WriteLine( " Line Number: {0}", sf->GetFileLineNumber().ToString() );
         
         // Note that the column number defaults to zero
         // when not initialized.
         Console::WriteLine( " Column Number: {0}", sf->GetFileColumnNumber().ToString() );
         Console::WriteLine( " Intermediate Language Offset: {0}", sf->GetILOffset().ToString() );
         Console::WriteLine( " Native Offset: {0}", sf->GetNativeOffset().ToString() );
         

      }
      Console::WriteLine();
      Console::WriteLine( "   ... throwing exception to next level ..." );
      Console::WriteLine( "-------------------------------------------------\n" );
      throw e;
   }

}

public void Level3Method()
{
   try 
   {
      ClassLevel4 nestedClass = new ClassLevel4();
      nestedClass.Level4Method();
   }
   catch (Exception e) 
   {
      Console.WriteLine(" Level3Method exception handler");

      // Build a stack trace from a dummy stack frame.
      // Explicitly specify the source file name and 
      // line number.
      StackTrace st = new StackTrace(new StackFrame("source.cs", 60));
      Console.WriteLine(" Stack trace with dummy stack frame: {0}", 
                  st.ToString());
      for(int i =0; i< st.FrameCount; i++ )
      {
         // Display the stack frame properties.
         StackFrame sf = st.GetFrame(i);
         Console.WriteLine(" File: {0}", sf.GetFileName());
         Console.WriteLine(" Line Number: {0}", 
            sf.GetFileLineNumber());
         // Note that the column number defaults to zero
         // when not initialized.
         Console.WriteLine(" Column Number: {0}", 
            sf.GetFileColumnNumber());
         if (sf.GetILOffset() != StackFrame.OFFSET_UNKNOWN)
         {
            Console.WriteLine(" Intermediate Language Offset: {0}", 
               sf.GetILOffset());
         }
         if (sf.GetNativeOffset() != StackFrame.OFFSET_UNKNOWN)
         {
            Console.WriteLine(" Native Offset: {0}", 
               sf.GetNativeOffset());
         }
      }
      Console.WriteLine();
      Console.WriteLine("   ... throwing exception to next level ...");
      Console.WriteLine("-------------------------------------------------\n");
      throw e;
   }
}
Public Sub Level3Method()
   Try
      Dim nestedClass As New ClassLevel4()
      nestedClass.Level4Method()
   Catch e As Exception
      Console.WriteLine(" Level3Method exception handler")
      
      ' Build a stack trace from a dummy stack frame.
      ' Explicitly specify the source file name and line number.
      Dim st As New StackTrace(New StackFrame("source.cs", 60))
      Console.WriteLine(" Stack trace with dummy stack frame: {0}", _
         st.ToString())
      Dim i As Integer
      For i = 0 To st.FrameCount - 1
         ' Display the stack frame properties.
         Dim sf As StackFrame = st.GetFrame(i)
         Console.WriteLine(" File: {0}", sf.GetFileName())
         Console.WriteLine(" Line Number: {0}", _
            sf.GetFileLineNumber())
         ' The column number defaults to zero when not initialized.
         Console.WriteLine(" Column Number: {0}", _
            sf.GetFileColumnNumber())
         If sf.GetILOffset <> StackFrame.OFFSET_UNKNOWN
            Console.WriteLine(" Intermediate Language Offset: {0}", _
                sf.GetILOffset())
         End If
         If sf.GetNativeOffset <> StackFrame.OFFSET_UNKNOWN
           Console.WriteLine(" Native Offset: {0}", _
               sf.GetNativeOffset())
         End If
      Next i 
      Console.WriteLine()
      Console.WriteLine("   ... throwing exception to next level ...")
      Console.WriteLine("-------------------------------------------------")
      Console.WriteLine()
      Throw e
   End Try
End Sub 'Level3Method

注釈

デバッガーの行のマッピングのロジックを使用したくない場合は、このコンス トラクターを使用します。Use this constructor when you do not want to use the debugger's line mapping logic.

StackFrame(String, Int32, Int32) StackFrame(String, Int32, Int32) StackFrame(String, Int32, Int32) StackFrame(String, Int32, Int32)

指定されたファイル名、行番号、および列番号だけを含む StackFrame クラスの新しいインスタンスを初期化します。Initializes a new instance of the StackFrame class that contains only the given file name, line number, and column number.

public:
 StackFrame(System::String ^ fileName, int lineNumber, int colNumber);
public StackFrame (string fileName, int lineNumber, int colNumber);
new System.Diagnostics.StackFrame : string * int * int -> System.Diagnostics.StackFrame
Public Sub New (fileName As String, lineNumber As Integer, colNumber As Integer)

パラメーター

fileName
String String String String

ファイル名。The file name.

lineNumber
Int32 Int32 Int32 Int32

指定したファイルの行番号。The line number in the specified file.

colNumber
Int32 Int32 Int32 Int32

指定したファイルの列番号。The column number in the specified file.

次の例では、使用、StackFrameコンス トラクター。The following example demonstrates the use of the StackFrame constructor. このコード例が示されている例の一部、StackFrameクラス。This code example is part of a larger example provided for the StackFrame class.

try
{
   ClassLevel5^ nestedClass = gcnew ClassLevel5;
   nestedClass->Level5Method();
}
catch ( Exception^ e ) 
{
   Console::WriteLine( " Level4Method exception handler" );
   
   // Build a stack trace from a dummy stack frame.
   // Explicitly specify the source file name, line number
   // and column number.
   StackTrace^ st = gcnew StackTrace( gcnew StackFrame( "source.cs",79,24 ) );
   Console::WriteLine( " Stack trace with dummy stack frame: {0}", st->ToString() );
   
   // Access the StackFrames explicitly to display the file
   // name, line number and column number properties.
   // StackTrace.ToString only includes the method name. 
   for ( int i = 0; i < st->FrameCount; i++ )
   {
      StackFrame^ sf = st->GetFrame( i );
      Console::WriteLine( " File: {0}", sf->GetFileName() );
      Console::WriteLine( " Line Number: {0}", sf->GetFileLineNumber().ToString() );
      Console::WriteLine( " Column Number: {0}", sf->GetFileColumnNumber().ToString() );

   }
   Console::WriteLine();
   Console::WriteLine( "   ... throwing exception to next level ..." );
   Console::WriteLine( "-------------------------------------------------\n" );
   throw e;
}


try 
{
   ClassLevel5 nestedClass = new ClassLevel5();
   nestedClass.Level5Method();
}
catch (Exception e) 
{
   Console.WriteLine(" Level4Method exception handler");

   // Build a stack trace from a dummy stack frame.
   // Explicitly specify the source file name, line number
   // and column number.
   StackTrace st = new StackTrace(new StackFrame("source.cs", 79, 24));
   Console.WriteLine(" Stack trace with dummy stack frame: {0}", 
                  st.ToString());

   // Access the StackFrames explicitly to display the file
   // name, line number and column number properties.
   // StackTrace.ToString only includes the method name. 
   for(int i =0; i< st.FrameCount; i++ )
   {
      StackFrame sf = st.GetFrame(i);
      Console.WriteLine(" File: {0}", sf.GetFileName());
      Console.WriteLine(" Line Number: {0}", 
         sf.GetFileLineNumber());
      Console.WriteLine(" Column Number: {0}", 
         sf.GetFileColumnNumber());
   }
   Console.WriteLine();
   Console.WriteLine("   ... throwing exception to next level ...");
   Console.WriteLine("-------------------------------------------------\n");
   throw e;
}
   Try
      Dim [nestedClass] As New ClassLevel5()
      [nestedClass].Level5Method()
   Catch e As Exception
      Console.WriteLine(" Level4Method exception handler")
      
      ' Build a stack trace from a dummy stack frame.
      ' Explicitly specify the source file name, line number
      ' and column number.
      Dim st As New StackTrace(New StackFrame("source.cs", 79, 24))
      Console.WriteLine(" Stack trace with dummy stack frame: {0}", _
         st.ToString())
      
      ' Access the StackFrames explicitly to display the file
      ' name, line number and column number properties.
      ' StackTrace.ToString only includes the method name. 
      Dim i As Integer
      For i = 0 To st.FrameCount - 1
         Dim sf As StackFrame = st.GetFrame(i)
         Console.WriteLine(" File: {0}", sf.GetFileName())
         Console.WriteLine(" Line Number: {0}", _
            sf.GetFileLineNumber())
         Console.WriteLine(" Column Number: {0}", _
            sf.GetFileColumnNumber())
      Next i
      Console.WriteLine()
      Console.WriteLine("   ... throwing exception to next level ...")
      Console.WriteLine("-------------------------------------------------")
      Console.WriteLine()
      Throw e
   End Try
End Sub 'Level4Method 

注釈

デバッガーの行のマッピングのロジックを使用したくない場合は、このコンス トラクターを使用します。Use this constructor when you do not want to use the debugger's line mapping logic.

適用対象