StackTrace.GetFrame メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > StackTrace.GetFrame メソッドの意味・解説 

StackTrace.GetFrame メソッド

指定したスタック フレーム取得します

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

Public Overridable Function
 GetFrame ( _
    index As Integer _
) As StackFrame
public virtual StackFrame GetFrame (
    int index
)
public:
virtual StackFrame^ GetFrame (
    int index
)
public StackFrame GetFrame (
    int index
)
public function GetFrame (
    index : int
) : StackFrame

パラメータ

index

要求されるスタック フレームインデックス

戻り値
指定したスタック フレーム

解説解説
使用例使用例

スタック トレース内の最初最後関数呼び出し表示するコード例次に示します

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 'Level5Method
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;
   }        
}
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() throws System.Exception
{
    try {
        ClassLevel6 nestedClass = new ClassLevel6();
        nestedClass.Level6Method();
    }
    catch (System.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.get_FrameCount() > 1) {
            // Display the highest-level function call 
            // in the trace.
            sf = st.GetFrame(st.get_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;
    }
} //Level5Method
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

StackTrace.GetFrame メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



StackTrace.GetFrame メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS