StackTrace.FrameCount Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan jumlah bingkai dalam pelacakan tumpukan.
public:
virtual property int FrameCount { int get(); };
public virtual int FrameCount { get; }
member this.FrameCount : int
Public Overridable ReadOnly Property FrameCount As Integer
Nilai Properti
Jumlah bingkai dalam pelacakan tumpukan.
Contoh
Contoh kode berikut menampilkan panggilan fungsi pertama dan terakhir dalam jejak tumpukan.
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
Berlaku untuk
Berkolaborasi dengan kami di GitHub
Sumber untuk konten ini dapat ditemukan di GitHub, yang juga dapat Anda gunakan untuk membuat dan meninjau masalah dan menarik permintaan. Untuk informasi selengkapnya, lihat panduan kontributor kami.