StackFrame.ToString Metode
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.
Membangun representasi pelacakan tumpukan yang dapat dibaca.
public:
override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String
Mengembalikan
Representasi pelacakan tumpukan yang dapat dibaca.
Contoh
Contoh berikut menunjukkan penggunaan ToString metode . Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk StackFrame kelas .
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
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.