次の方法で共有


StackFrame.ToString メソッド

スタック トレースの読み取り可能な形式を構築します。

Overrides Public Function ToString() As String
[C#]
public override string ToString();
[C++]
public: String* ToString();
[JScript]
public override function ToString() : String;

戻り値

読み取り可能な形式を返します。

使用例

[Visual Basic, C#, C++] ToString メソッドを使用する方法を次のコード例に示します。

 
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

[C#] 
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;
   }
}

[C++] 
void InternalMethod()
{
   try
   {
      ClassLevel2 *nestedClass = new ClassLevel2();
      nestedClass->Level2Method();
   }
   catch (Exception *e)
   {
      Console::WriteLine(S" 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(S" Stack trace for next level frame: {0}", 
         st->ToString());
      Console::WriteLine(S" Stack frame for next level: ");
      Console::WriteLine(S"   {0}", st->GetFrame(0)->ToString());

      Console::WriteLine(S" Line Number: {0}", 
         st->GetFrame(0)->GetFileLineNumber().ToString());

      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 ファミリ

参照

StackFrame クラス | StackFrame メンバ | System.Diagnostics 名前空間