指定したスタック フレームを取得します。
Public Overridable Function GetFrame( _
ByVal index As Integer _) As StackFrame
[C#]
public virtual StackFrame GetFrame(intindex);
[C++]
public: virtual StackFrame* GetFrame(intindex);
[JScript]
public function GetFrame(
index : int) : StackFrame;
パラメータ
- index
要求されるスタック フレームのインデックス。
戻り値
指定したスタック フレーム。
解説
スタック フレームには、最後にプッシュされるスタック フレームとして、0 から始まる番号が付けられます。
使用例
[Visual Basic, C#, C++] このメソッドの一般的な使用方法の 1 つを次のコード例で示します。
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
[C#]
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;
}
}
[C++]
void Level5Method()
{
try
{
ClassLevel6 *nestedClass = new ClassLevel6();
nestedClass->Level6Method();
}
catch (Exception *e)
{
Console::WriteLine(S" Level5Method exception handler");
StackTrace *st = new StackTrace();
// Display the most recent function call.
StackFrame *sf = st->GetFrame(0);
Console::WriteLine();
Console::WriteLine(S" Exception in method: ");
Console::WriteLine(S" {0}", sf->GetMethod());
if (st->FrameCount >1)
{
// Display the highest-level function call
// in the trace.
sf = st->GetFrame(st->FrameCount-1);
Console::WriteLine(S" Original function call at top of call stack):");
Console::WriteLine(S" {0}", sf->GetMethod());
}
Console::WriteLine();
Console::WriteLine(S" ... throwing exception to next level ...");
Console::WriteLine(S"-------------------------------------------------\n");
throw e;
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン
をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
StackTrace クラス | StackTrace メンバ | System.Diagnostics 名前空間 | StackFrame