stack traceとは? わかりやすく解説

Weblio 辞書 > コンピュータ > IT用語辞典 > stack traceの意味・解説 

スタックトレース

【英】stack trace

スタックトレースとは、プログラムの実行過程記録したスタックフレーム記録しておくことである。

スタックフレームは、関数呼ばれるために生成されるその内容システムコンパイラなどの実装によって異なるが、呼び出し元へ戻りアドレスローカル変数などによって構成されている。

スタックトレースでは、プログラムデバック時に実行過程プレイバックするための情報として活用でできる。関数名情報さえあれば、スタックトレースから問題発生時に最後に実行していた関数名がわかる。また、プログラムが異常動作結果により停止した場合には、スタックトレースにより、想定外関数動作していたことや、思わぬルート実行されていたことなどが分かる場合があり、問題解決重要な手がかりになる。

プログラミングのほかの用語一覧
開発環境:  シンボリックデバッガ  条件コンパイル  シングルステップ実行  スタックトレース  デバッガ  デバッグ  トレース

StackTrace クラス

スタック トレース表しますスタック トレースは、順番並べられ1 つまたは複数スタック フレームコレクションです。

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

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class StackTrace
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class StackTrace
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class StackTrace
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class StackTrace
SerializableAttribute 
ComVisibleAttribute(true) 
public class StackTrace
解説解説
使用例使用例

単純な StackTrace作成し、そのフレーム反復処理してデバッグ情報診断情報取得する方法次のコンソール アプリケーション示します

Imports System
Imports System.Diagnostics

Class StackTraceSample
   
    <STAThread()>  _
    Public Shared Sub Main()

        Dim sample As New
 StackTraceSample()
        Try
   
            sample.MyPublicMethod()
        Catch
            ' Create a StackTrace that captures
            ' filename, line number, and column
            ' information for the current thread.
            Dim st As New
 StackTrace(True)
            Dim i As Integer

            For i = 0 To st.FrameCount - 1

                ' Note that high up the call stack, there is only
                ' one stack frame.
                Dim sf As StackFrame = st.GetFrame(i)
                Console.WriteLine()
                Console.WriteLine("High up the call stack, Method:
 {0}", _
                    sf.GetMethod())
            
                Console.WriteLine("High up the call stack, Line
 Number: {0}", _
                    sf.GetFileLineNumber())
            Next i
        End Try
    End Sub
   
   Public Sub MyPublicMethod()
      MyProtectedMethod()
   End Sub
    
   Protected Sub MyProtectedMethod()
      Dim mic As New MyInternalClass()
      mic.ThrowsException()
   End Sub
   
   
   Class MyInternalClass
      
      Public Sub ThrowsException()
         Try
            Throw New Exception("A
 problem was encountered.")
         Catch e As Exception

            ' Create a StackTrace that captures filename,
            ' line number and column information.
            Dim st As New
 StackTrace(True)

            Dim stackIndent As String
 = ""
            Dim i As Integer
            For i = 0 To st.FrameCount - 1
               ' Note that at this level, there are four
               ' stack frames, one for each method invocation.
               Dim sf As StackFrame = st.GetFrame(i)
               Console.WriteLine()
               Console.WriteLine(stackIndent + " Method: {0}",
 _
                   sf.GetMethod())
               Console.WriteLine(stackIndent + " File: {0}",
 _
                   sf.GetFileName())
               Console.WriteLine(stackIndent + " Line Number:
 {0}", _
                   sf.GetFileLineNumber())
               stackIndent += "  "
            Next i
            Throw e
         End Try
      End Sub
   End Class
End Class


' This console application produces the following output when
' compiled with the Debug configuration.
'   
'    Method: Void ThrowsException()
'    File: c:\pp\samples\stacktraceframe\myclass.vb
'    Line Number: 55
' 
'      Method: Void MyProtectedMethod()
'      File: c:\pp\samples\stacktraceframe\myclass.vb
'      Line Number: 42
' 
'        Method: Void MyPublicMethod()
'        File: c:\pp\samples\stacktraceframe\myclass.vb
'        Line Number: 37
' 
'          Method: Void Main(System.String[])
'          File: c:\pp\samples\stacktraceframe\myclass.vb
'          Line Number: 13
' 
'   High up the call stack, Method: Void Main(System.String[])
'   High up the call stack, Line Number: 18
' 
' 
' This console application produces the following output when
' compiled with the Release configuration.
' 
'    Method: Void ThrowsException()
'    File:
'    Line Number: 0
' 
'      Method: Void Main(System.String[])
'      File:
'      Line Number: 0
' 
'   High up the call stack, Method: Void Main()
'   High up the call stack, Line Number: 0
'
using System;
using System.Diagnostics;

class StackTraceSample
{
    [STAThread]
    static void Main(string[]
 args)
    {
        StackTraceSample sample = new StackTraceSample();
        try
        {
            sample.MyPublicMethod();
        }
        catch (Exception)
        {
            // Create a StackTrace that captures
            // filename, line number, and column
            // information for the current thread.
            StackTrace st = new StackTrace(true);
            for(int i =0; i< st.FrameCount;
 i++ )
            {
                // Note that high up the call stack, there is only
                // one stack frame.
                StackFrame sf = st.GetFrame(i);
                Console.WriteLine();
                Console.WriteLine("High up the call stack, Method: {0}"
,
                    sf.GetMethod());

                Console.WriteLine("High up the call stack, Line Number: {0}"
,
                    sf.GetFileLineNumber());
            }
        }
    }

    public void MyPublicMethod () 
    { 
        MyProtectedMethod(); 
    }

    protected void MyProtectedMethod ()
    {
        MyInternalClass mic = new MyInternalClass();
        mic.ThrowsException();
    }

    class MyInternalClass
    {
        public void ThrowsException()
        {
            try
            {
                throw new Exception("A problem was encountered.");
            }
            catch (Exception e)
            {
                // Create a StackTrace that captures filename,
                // line number and column information.
                StackTrace st = new StackTrace(true);
                string stackIndent = "";
                for(int i =0; i< st.FrameCount;
 i++ )
                {
                    // Note that at this level, there are four
                    // stack frames, one for each method invocation.
                    StackFrame sf = st.GetFrame(i);
                    Console.WriteLine();
                    Console.WriteLine(stackIndent + " Method: {0}",
                        sf.GetMethod() );
                    Console.WriteLine(  stackIndent + " File: {0}", 
                        sf.GetFileName());
                    Console.WriteLine(  stackIndent + " Line Number: {0}"
,
                        sf.GetFileLineNumber());
                    stackIndent += "  ";
                }
                throw e;
            }
        }
    }
}

/*
This console application produces the following output when
compiled with the Debug configuration.
  
   Method: Void ThrowsException()
   File: c:\samples\stacktraceframe\myclass.cs
   Line Number: 59

     Method: Void MyProtectedMethod()
     File: c:\samples\stacktraceframe\myclass.cs
     Line Number: 45

       Method: Void MyPublicMethod()
       File: c:\samples\stacktraceframe\myclass.cs
       Line Number: 39

         Method: Void Main(System.String[])
         File: c:\samples\stacktraceframe\myclass.cs
         Line Number: 13

  High up the call stack, Method: Void Main(System.String[])
  High up the call stack, Line Number: 20


This console application produces the following output when
compiled with the Release configuration.

   Method: Void ThrowsException()
   File:
   Line Number: 0

     Method: Void Main(System.String[])
     File:
     Line Number: 0

  High up the call stack, Method: Void Main(System.String[])
  High up the call stack, Line Number: 0

*/
#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
ref class StackTraceSample
{
private:
   ref class MyInternalClass
   {
   public:
      void ThrowsException()
      {
         try
         {
            throw gcnew Exception( "A problem was encountered." );
         }
         catch ( Exception^ e ) 
         {
            
            // Create a StackTrace that captures
            // filename, line number, and column
            // information for the current thread.
            StackTrace^ st = gcnew StackTrace( true );
            String^ stackIndent = "";
            for ( int i = 0; i < st->FrameCount;
 i++ )
            {
               
               // Note that at this level, there are five
               // stack frames, one for each method invocation.
               StackFrame^ sf = st->GetFrame( i );
               Console::WriteLine();
               Console::WriteLine( "{0}Method: {1}", stackIndent, sf->GetMethod()
 );
               Console::WriteLine( "{0}File: {1}", stackIndent, sf->GetFileName()
 );
               Console::WriteLine( "{0}Line Number: {1}", stackIndent,
 sf->GetFileLineNumber().ToString() );
               stackIndent = String::Concat( stackIndent, "  " );

            }
            throw e;
         }

      }

   };


protected:
   void MyProtectedMethod()
   {
      MyInternalClass^ mic = gcnew MyInternalClass;
      mic->ThrowsException();
   }


public:
   void MyPublicMethod()
   {
      MyProtectedMethod();
   }

};

int main()
{
   StackTraceSample^ sample = gcnew StackTraceSample;
   try
   {
      sample->MyPublicMethod();
   }
   catch ( Exception^ ) 
   {
      
      // Create a StackTrace that captures
      // filename, line number, and column
      // information for the current thread.
      StackTrace^ st = gcnew StackTrace( true );
      for ( int i = 0; i < st->FrameCount;
 i++ )
      {
         
         // For an executable built from C++, there
         // are two stack frames here: one for main,
         // and one for the _mainCRTStartup stub. 
         StackFrame^ sf = st->GetFrame( i );
         Console::WriteLine();
         Console::WriteLine( "High up the call stack, Method: {0}", sf->GetMethod()->ToString()
 );
         Console::WriteLine( "High up the call stack, Line Number: {0}",
 sf->GetFileLineNumber().ToString() );

      }
   }

}

/*
This console application produces the following output when
compiled with the Debug configuration.

  Method: Void ThrowsException()
  File: c:\samples\stacktraceframe\myclass.cpp
  Line Number: 20

    Method: Void MyProtectedMethod()
    File: c:\samples\stacktraceframe\myclass.cpp
    Line Number: 45

      Method: Void MyPublicMethod()
      File: c:\samples\stacktraceframe\myclass.cpp
      Line Number: 50
 
        Method: Int32 main()
        File: c:\samples\stacktraceframe\myclass.cpp
        Line Number: 56

          Method: UInt32 _mainCRTStartup()
          File:
          Line Number: 0

  High up the call stack, Method: Int32 main()
  High up the call stack, Line Number: 62

  High up the call stack, Method: UInt32 _mainCRTStartup()
  High up the call stack, Line Number: 0

This console application produces the following output when
compiled with the Release configuration.

  Method: Void ThrowsException()
  File:
  Line Number: 0

    Method: Int32 main()
    File:
    Line Number: 0

      Method: UInt32 _mainCRTStartup()
      File:
      Line Number: 0

  High up the call stack, Method: Int32 main()
  High up the call stack, Line Number: 0

  High up the call stack, Method: UInt32 _mainCRTStartup()
  High up the call stack, Line Number: 0

*/
import System.*;
import System.Diagnostics.*;

class StackTraceSample
{
    /** @attribute STAThread()
     */
    public static void main(String[]
 args)
    {
        StackTraceSample sample = new StackTraceSample();
        try {
            sample.MyPublicMethod();
        }
        catch (System.Exception exp) {
            // Create a StackTrace that captures
            // filename, line number, and column
            // information for the current thread.
            StackTrace st = new StackTrace(true);
            for (int i = 0; i < st.get_FrameCount();
 i++) {
                // Note that high up the call stack, there is only
                // one stack frame.
                StackFrame sf = st.GetFrame(i);
                Console.WriteLine();
                Console.WriteLine("High up the call stack, Method: {0}"
,
                    sf.GetMethod());
                Console.WriteLine("High up the call stack, Line Number: {0}"
,
                    (Int32)sf.GetFileLineNumber());
            }
        }
    } //main

    public void MyPublicMethod() throws System.Exception
    {
        MyProtectedMethod();
    } //MyPublicMethod

    protected void MyProtectedMethod() throws
 System.Exception
    {
        MyInternalClass mic = new MyInternalClass();
        mic.ThrowsException();
    } //MyProtectedMethod

    class MyInternalClass
    {
        public void ThrowsException() throws
 System.Exception
        {
            try {
                throw new System.Exception("A problem was
 encountered.");
            }
            catch (System.Exception e) {
                // Create a StackTrace that captures filename,
                // line number and column information.
                StackTrace st = new StackTrace(true);
                String stackIndent = "";
                for (int i = 0; i < st.get_FrameCount();
 i++) {
                    // Note that at this level, there are four
                    // stack frames, one for each method invocation.
                    StackFrame sf = st.GetFrame(i);
                    Console.WriteLine();
                    Console.WriteLine(stackIndent + " Method: {0}", 
                        sf.GetMethod());
                    Console.WriteLine(stackIndent + " File: {0}", 
                        sf.GetFileName());
                    Console.WriteLine(stackIndent + " Line Number: {0}",
 
                        (Int32)sf.GetFileLineNumber());
                    stackIndent += "  ";
                }
                throw e;
            }
        } //ThrowsException
    } //MyInternalClass
} //StackTraceSample

/*
This console application produces the following output when
compiled with the Debug configuration.
   
 Method: Void ThrowsException()
 File: c:\samples\stacktraceframe\myclass.jsl
 Line Number: 57

   Method: Void MyProtectedMethod()
   File: c:\samples\stacktraceframe\myclass.jsl
   Line Number: 43

     Method: Void MyPublicMethod()
     File: c:\samples\stacktraceframe\myclass.jsl
     Line Number: 37

       Method: Void main(System.String[])
       File: c:\samples\stacktraceframe\myclass.jsl
       Line Number: 14

High up the call stack, Method: Void main(System.String[])
High up the call stack, Line Number: 21

This console application produces the following output when
compiled with the Release configuration.

   
 Method: Void ThrowsException()
 File:
 Line Number: 0

   Method: Void MyProtectedMethod()
   File:
   Line Number: 0

     Method: Void MyPublicMethod()
     File:
     Line Number: 0

       Method: Void main(System.String[])
       File:
       Line Number: 0

High up the call stack, Method: Void main(System.String[])
High up the call stack, Line Number: 0

*/
継承階層継承階層
System.Object
  System.Diagnostics.StackTrace
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
StackTrace メンバ
System.Diagnostics 名前空間
Exception.StackTrace
Environment.StackTrace
ServerFault.StackTrace

StackTrace コンストラクタ ()

StackTrace クラス新しインスタンス呼び出し元のフレームから初期化します。

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

public StackTrace ()
public:
StackTrace ()
public StackTrace ()
解説解説
使用例使用例

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

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

StackTrace コンストラクタ (Exception)

指定した例外オブジェクト使用して、StackTrace クラス新しインスタンス初期化します。

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

例外例外
例外種類条件

ArgumentNullException

e パラメータnull 参照 (Visual Basic では Nothing) です。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

StackTrace コンストラクタ (StackFrame)

単一フレーム格納している StackTrace クラス新しインスタンス初期化します。

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

Public Sub New ( _
    frame As StackFrame _
)
Dim frame As StackFrame

Dim instance As New StackTrace(frame)
public StackTrace (
    StackFrame frame
)
public:
StackTrace (
    StackFrame^ frame
)
public StackTrace (
    StackFrame frame
)
public function StackTrace (
    frame : StackFrame
)

パラメータ

frame

StackTrace オブジェクト格納するフレーム

解説解説
使用例使用例

スタック トレース情報イベント ログ エントリに書き込むコード例次に示します

Dim frame As New StackFrame(1,
 True)
Dim strace As New StackTrace(frame)
            

EventLog.WriteEntry(frame.GetMethod().Name, _
                    strace.ToString(), _
                    EventLogEntryType.Warning)
StackFrame fr = new StackFrame(1,true);
StackTrace st = new StackTrace(fr);
EventLog.WriteEntry(fr.GetMethod().Name,
                    st.ToString(),
                    EventLogEntryType.Warning);
StackFrame^ fr = gcnew StackFrame( 1,true );
StackTrace^ st = gcnew StackTrace( fr );
EventLog::WriteEntry( fr->GetMethod()->Name, st->ToString(), EventLogEntryType::Warning
 );
StackFrame fr = new StackFrame(1, true);
StackTrace st = new StackTrace(fr);
EventLog.WriteEntry(fr.GetMethod().get_Name(), st.ToString(),
    EventLogEntryType.Warning);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

StackTrace コンストラクタ (Boolean)

StackTrace クラス新しインスタンス呼び出し元のフレームから初期化しオプションソース情報キャプチャます。

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

Public Sub New ( _
    fNeedFileInfo As Boolean _
)
Dim fNeedFileInfo As Boolean

Dim instance As New StackTrace(fNeedFileInfo)
public StackTrace (
    bool fNeedFileInfo
)
public:
StackTrace (
    bool fNeedFileInfo
)
public StackTrace (
    boolean fNeedFileInfo
)
public function StackTrace (
    fNeedFileInfo : boolean
)

パラメータ

fNeedFileInfo

ファイル名行番号、および列番号をキャプチャする場合trueそれ以外場合false

解説解説
使用例使用例

さまざまな StackTrace コンストラクタ メソッドコード例次に示します

Public Sub Level2Method()
   Try
      Dim nestedClass As New
 ClassLevel3
      nestedClass.Level3Method()
   
   Catch e As Exception
      Console.WriteLine(" Level2Method exception handler")
      
      ' Display the full call stack at this level.
      Dim st1 As New StackTrace(True)
      Console.WriteLine(" Stack trace for this level: {0}",
 _
         st1.ToString())
      
      ' Build a stack trace from one frame, skipping the current
      ' frame and using the next frame.
      Dim st2 As New StackTrace(New
 StackFrame(1, True))
      Console.WriteLine(" Stack trace built with next level frame:
 {0}", _
          st2.ToString())
      
      ' Build a stack trace skipping the current frame, and
      ' including all the other frames.
      Dim st3 As New StackTrace(1,
 True)
      Console.WriteLine(" Stack trace built from the next level
 up: {0}", _
          st3.ToString())
      
      Console.WriteLine()
      Console.WriteLine("   ... throwing exception to next level
 ...")
      Console.WriteLine("-------------------------------------------------")
      Console.WriteLine()
      Throw e
   End Try
End Sub 'Level2Method
public void Level2Method()
{
   try 
   {
      ClassLevel3 nestedClass = new ClassLevel3();
      nestedClass.Level3Method();

   }
   catch (Exception e) 
   {
      Console.WriteLine(" Level2Method exception handler");

      // Display the full call stack at this level.
      StackTrace st1 = new StackTrace(true);
      Console.WriteLine(" Stack trace for this
 level: {0}",
         st1.ToString());

      // Build a stack trace from one frame, skipping the current
      // frame and using the next frame.
      StackTrace st2 = new StackTrace(new StackFrame(1,
 true));
      Console.WriteLine(" Stack trace built with next level frame: {0}"
,
         st2.ToString());

      // Build a stack trace skipping the current frame, and
      // including all the other frames.
      StackTrace st3 = new StackTrace(1, true);
      Console.WriteLine(" Stack trace built from the next level up: {0}"
,
         st3.ToString());

      Console.WriteLine();
      Console.WriteLine("   ... throwing exception to next level ...");
      Console.WriteLine("-------------------------------------------------\n");
      throw e;
   }
}
void Level2Method()
{
   try
   {
      ClassLevel3^ nestedClass = gcnew ClassLevel3;
      nestedClass->Level3Method();
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( " Level2Method exception handler" );
      
      // Display the full call stack at this level.
      StackTrace^ st1 = gcnew StackTrace( true );
      Console::WriteLine( " Stack trace for this
 level: {0}", st1->ToString() );
      
      // Build a stack trace from one frame, skipping the
      // current frame and using the next frame.
      StackTrace^ st2 = gcnew StackTrace( gcnew StackFrame( 1,true
 ) );
      Console::WriteLine( " Stack trace built with next level frame: {0}",
 st2->ToString() );
      
      // Build a stack trace skipping the current frame, and
      // including all the other frames.
      StackTrace^ st3 = gcnew StackTrace( 1,true );
      Console::WriteLine( " Stack trace built from the next level up: {0}",
 st3->ToString() );
      Console::WriteLine();
      Console::WriteLine( "   ... throwing exception to next level ..."
 );
      Console::WriteLine( "-------------------------------------------------\n"
 );
      throw e;
   }

}

public void Level2Method() throws System.Exception
{
    try {
        ClassLevel3 nestedClass = new ClassLevel3();
        nestedClass.Level3Method();
    }
    catch (System.Exception e) {
        Console.WriteLine(" Level2Method exception handler");

        // Display the full call stack at this level.
        StackTrace st1 = new StackTrace(true);
        Console.WriteLine(" Stack trace for this
 level: {0}", 
            st1.ToString());

        // Build a stack trace from one frame, skipping the current
        // frame and using the next frame.
        StackTrace st2 = new StackTrace(new StackFrame(1,
 true));
        Console.WriteLine(" Stack trace built with next level frame: {0}"
,
            st2.ToString());

        // Build a stack trace skipping the current frame, and
        // including all the other frames.
        StackTrace st3 = new StackTrace(1, true);
        Console.WriteLine(" Stack trace built from the next level up: {0}"
,
            st3.ToString());
        Console.WriteLine();
        Console.WriteLine(" ... throwing exception to next level...");
        Console.WriteLine("--------------------------------------------"
            + "-----\n");
        throw e;
    }
} //Level2Method
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

StackTrace コンストラクタ (Exception, Int32, Boolean)

指定した例外オブジェクト使用して、StackTrace クラス新しインスタンス初期化し指定したフレーム数をスキップしたり、必要に応じてソース情報取得したできます

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

Public Sub New ( _
    e As Exception, _
    skipFrames As Integer, _
    fNeedFileInfo As Boolean _
)
Dim e As Exception
Dim skipFrames As Integer
Dim fNeedFileInfo As Boolean

Dim instance As New StackTrace(e,
 skipFrames, fNeedFileInfo)
public StackTrace (
    Exception e,
    int skipFrames,
    bool fNeedFileInfo
)
public:
StackTrace (
    Exception^ e, 
    int skipFrames, 
    bool fNeedFileInfo
)
public StackTrace (
    Exception e, 
    int skipFrames, 
    boolean fNeedFileInfo
)
public function StackTrace (
    e : Exception, 
    skipFrames : int, 
    fNeedFileInfo : boolean
)

パラメータ

e

スタック トレース構築する基となる例外オブジェクト

skipFrames

トレース開始するスタックまでのフレーム数。

fNeedFileInfo

ファイル名行番号、および列番号をキャプチャする場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentNullException

e パラメータnull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

skipFrames パラメータが負の値です。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

StackTrace コンストラクタ (Exception, Boolean)

指定した例外オブジェクト使用して StackTrace クラス新しインスタンス初期化しオプションソース情報キャプチャます。

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

Public Sub New ( _
    e As Exception, _
    fNeedFileInfo As Boolean _
)
Dim e As Exception
Dim fNeedFileInfo As Boolean

Dim instance As New StackTrace(e,
 fNeedFileInfo)
public StackTrace (
    Exception e,
    bool fNeedFileInfo
)
public:
StackTrace (
    Exception^ e, 
    bool fNeedFileInfo
)
public StackTrace (
    Exception e, 
    boolean fNeedFileInfo
)
public function StackTrace (
    e : Exception, 
    fNeedFileInfo : boolean
)

パラメータ

e

スタック トレース構築する基となる例外オブジェクト

fNeedFileInfo

ファイル名行番号、および列番号をキャプチャする場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentNullException

e パラメータnull 参照 (Visual Basic では Nothing) です。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

StackTrace コンストラクタ (Int32, Boolean)

呼び出し元のフレームから StackTrace クラス新しインスタンス初期化し指定した数のフレームスキップしたり、必要に応じてソース情報取得したできます

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

Public Sub New ( _
    skipFrames As Integer, _
    fNeedFileInfo As Boolean _
)
Dim skipFrames As Integer
Dim fNeedFileInfo As Boolean

Dim instance As New StackTrace(skipFrames,
 fNeedFileInfo)
public StackTrace (
    int skipFrames,
    bool fNeedFileInfo
)
public:
StackTrace (
    int skipFrames, 
    bool fNeedFileInfo
)
public StackTrace (
    int skipFrames, 
    boolean fNeedFileInfo
)
public function StackTrace (
    skipFrames : int, 
    fNeedFileInfo : boolean
)

パラメータ

skipFrames

トレース開始するスタックまでのフレーム数。

fNeedFileInfo

ファイル名行番号、および列番号をキャプチャする場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentOutOfRangeException

skipFrames パラメータが負の値です。

解説解説
使用例使用例

さまざまな StackTrace コンストラクタ メソッドコード例次に示します

Public Sub Level2Method()
   Try
      Dim nestedClass As New
 ClassLevel3
      nestedClass.Level3Method()
   
   Catch e As Exception
      Console.WriteLine(" Level2Method exception handler")
      
      ' Display the full call stack at this level.
      Dim st1 As New StackTrace(True)
      Console.WriteLine(" Stack trace for this level: {0}",
 _
         st1.ToString())
      
      ' Build a stack trace from one frame, skipping the current
      ' frame and using the next frame.
      Dim st2 As New StackTrace(New
 StackFrame(1, True))
      Console.WriteLine(" Stack trace built with next level frame:
 {0}", _
          st2.ToString())
      
      ' Build a stack trace skipping the current frame, and
      ' including all the other frames.
      Dim st3 As New StackTrace(1,
 True)
      Console.WriteLine(" Stack trace built from the next level
 up: {0}", _
          st3.ToString())
      
      Console.WriteLine()
      Console.WriteLine("   ... throwing exception to next level
 ...")
      Console.WriteLine("-------------------------------------------------")
      Console.WriteLine()
      Throw e
   End Try
End Sub 'Level2Method
public void Level2Method()
{
   try 
   {
      ClassLevel3 nestedClass = new ClassLevel3();
      nestedClass.Level3Method();

   }
   catch (Exception e) 
   {
      Console.WriteLine(" Level2Method exception handler");

      // Display the full call stack at this level.
      StackTrace st1 = new StackTrace(true);
      Console.WriteLine(" Stack trace for this
 level: {0}",
         st1.ToString());

      // Build a stack trace from one frame, skipping the current
      // frame and using the next frame.
      StackTrace st2 = new StackTrace(new StackFrame(1,
 true));
      Console.WriteLine(" Stack trace built with next level frame: {0}"
,
         st2.ToString());

      // Build a stack trace skipping the current frame, and
      // including all the other frames.
      StackTrace st3 = new StackTrace(1, true);
      Console.WriteLine(" Stack trace built from the next level up: {0}"
,
         st3.ToString());

      Console.WriteLine();
      Console.WriteLine("   ... throwing exception to next level ...");
      Console.WriteLine("-------------------------------------------------\n");
      throw e;
   }
}
void Level2Method()
{
   try
   {
      ClassLevel3^ nestedClass = gcnew ClassLevel3;
      nestedClass->Level3Method();
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( " Level2Method exception handler" );
      
      // Display the full call stack at this level.
      StackTrace^ st1 = gcnew StackTrace( true );
      Console::WriteLine( " Stack trace for this
 level: {0}", st1->ToString() );
      
      // Build a stack trace from one frame, skipping the
      // current frame and using the next frame.
      StackTrace^ st2 = gcnew StackTrace( gcnew StackFrame( 1,true
 ) );
      Console::WriteLine( " Stack trace built with next level frame: {0}",
 st2->ToString() );
      
      // Build a stack trace skipping the current frame, and
      // including all the other frames.
      StackTrace^ st3 = gcnew StackTrace( 1,true );
      Console::WriteLine( " Stack trace built from the next level up: {0}",
 st3->ToString() );
      Console::WriteLine();
      Console::WriteLine( "   ... throwing exception to next level ..."
 );
      Console::WriteLine( "-------------------------------------------------\n"
 );
      throw e;
   }

}

public void Level2Method() throws System.Exception
{
    try {
        ClassLevel3 nestedClass = new ClassLevel3();
        nestedClass.Level3Method();
    }
    catch (System.Exception e) {
        Console.WriteLine(" Level2Method exception handler");

        // Display the full call stack at this level.
        StackTrace st1 = new StackTrace(true);
        Console.WriteLine(" Stack trace for this
 level: {0}", 
            st1.ToString());

        // Build a stack trace from one frame, skipping the current
        // frame and using the next frame.
        StackTrace st2 = new StackTrace(new StackFrame(1,
 true));
        Console.WriteLine(" Stack trace built with next level frame: {0}"
,
            st2.ToString());

        // Build a stack trace skipping the current frame, and
        // including all the other frames.
        StackTrace st3 = new StackTrace(1, true);
        Console.WriteLine(" Stack trace built from the next level up: {0}"
,
            st3.ToString());
        Console.WriteLine();
        Console.WriteLine(" ... throwing exception to next level...");
        Console.WriteLine("--------------------------------------------"
            + "-----\n");
        throw e;
    }
} //Level2Method
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

StackTrace コンストラクタ

StackTrace クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
StackTrace () StackTrace クラス新しインスタンス呼び出し元のフレームから初期化します。
StackTrace (Boolean) StackTrace クラス新しインスタンス呼び出し元のフレームから初期化しオプションソース情報キャプチャます。
StackTrace (Exception) 指定した例外オブジェクト使用してStackTrace クラス新しインスタンス初期化します。
StackTrace (Int32) 呼び出し元のフレームから StackTrace クラス新しインスタンス初期化し指定した数のフレームスキップします。
StackTrace (StackFrame) 単一フレーム格納している StackTrace クラス新しインスタンス初期化します。
StackTrace (Exception, Boolean) 指定した例外オブジェクト使用して StackTrace クラス新しインスタンス初期化しオプションソース情報キャプチャます。
StackTrace (Exception, Int32) 指定した例外オブジェクト使用して StackTrace クラス新しインスタンス初期化し指定した数のフレームスキップします。
StackTrace (Int32, Boolean) 呼び出し元のフレームから StackTrace クラス新しインスタンス初期化し指定した数のフレームスキップしたり、必要に応じてソース情報取得したできます
StackTrace (Thread, Boolean) 指定したスレッド用に StackTrace クラス新しインスタンス初期化しオプションソース情報キャプチャます。
StackTrace (Exception, Int32, Boolean) 指定した例外オブジェクト使用してStackTrace クラス新しインスタンス初期化し指定したフレーム数をスキップしたり、必要に応じてソース情報取得したできます
参照参照

関連項目

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

StackTrace コンストラクタ (Thread, Boolean)

指定したスレッド用に StackTrace クラス新しインスタンス初期化しオプションソース情報キャプチャます。

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

Public Sub New ( _
    targetThread As Thread, _
    needFileInfo As Boolean _
)
Dim targetThread As Thread
Dim needFileInfo As Boolean

Dim instance As New StackTrace(targetThread,
 needFileInfo)
public StackTrace (
    Thread targetThread,
    bool needFileInfo
)
public:
StackTrace (
    Thread^ targetThread, 
    bool needFileInfo
)
public StackTrace (
    Thread targetThread, 
    boolean needFileInfo
)
public function StackTrace (
    targetThread : Thread, 
    needFileInfo : boolean
)

パラメータ

targetThread

スタック トレース要求するスレッド

needFileInfo

ファイル名行番号、および列番号をキャプチャする場合trueそれ以外場合false

例外例外
例外種類条件

ThreadStateException

スレッド targetThread中断されていません。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

StackTrace コンストラクタ (Exception, Int32)

指定した例外オブジェクト使用して StackTrace クラス新しインスタンス初期化し指定した数のフレームスキップします。

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

Public Sub New ( _
    e As Exception, _
    skipFrames As Integer _
)
Dim e As Exception
Dim skipFrames As Integer

Dim instance As New StackTrace(e,
 skipFrames)
public StackTrace (
    Exception e,
    int skipFrames
)
public:
StackTrace (
    Exception^ e, 
    int skipFrames
)
public StackTrace (
    Exception e, 
    int skipFrames
)
public function StackTrace (
    e : Exception, 
    skipFrames : int
)

パラメータ

e

スタック トレース構築する基となる例外オブジェクト

skipFrames

トレース開始するスタックまでのフレーム数。

例外例外
例外種類条件

ArgumentNullException

e パラメータnull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

skipFrames パラメータが負の値です。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

StackTrace コンストラクタ (Int32)

呼び出し元のフレームから StackTrace クラス新しインスタンス初期化し指定した数のフレームスキップします。

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

Public Sub New ( _
    skipFrames As Integer _
)
Dim skipFrames As Integer

Dim instance As New StackTrace(skipFrames)
public StackTrace (
    int skipFrames
)
public:
StackTrace (
    int skipFrames
)
public StackTrace (
    int skipFrames
)
public function StackTrace (
    skipFrames : int
)

パラメータ

skipFrames

トレース開始するスタックまでのフレーム数。

例外例外
例外種類条件

ArgumentOutOfRangeException

skipFrames パラメータが負の値です。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

StackTrace フィールド


パブリック フィールドパブリック フィールド

  名前 説明
パブリック フィールド METHODS_TO_SKIP スタック トレースから省略する既定メソッド数を定義します。このフィールド定数です。
参照参照

関連項目

StackTrace クラス
System.Diagnostics 名前空間
Exception.StackTrace
Environment.StackTrace
ServerFault.StackTrace

StackTrace プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

StackTrace クラス
System.Diagnostics 名前空間
Exception.StackTrace
Environment.StackTrace
ServerFault.StackTrace

StackTrace メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

StackTrace クラス
System.Diagnostics 名前空間
Exception.StackTrace
Environment.StackTrace
ServerFault.StackTrace

StackTrace メンバ

スタック トレース表しますスタック トレースは、順番並べられ1 つまたは複数スタック フレームコレクションです。

StackTrace データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック フィールドパブリック フィールド
  名前 説明
パブリック フィールド METHODS_TO_SKIP スタック トレースから省略する既定メソッド数を定義します。このフィールド定数です。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

StackTrace クラス
System.Diagnostics 名前空間
Exception.StackTrace
Environment.StackTrace
ServerFault.StackTrace

スタックトレース

(stack trace から転送)

出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2023/04/29 10:33 UTC 版)

コンピュータにおいて、スタックトレース英語: stack trace)とは、プログラムの実行中の特定の時点でのアクティブなスタックフレームのレポートである。スタックバックトレース英語: stack backtrace[1])、スタックトレースバック英語: stack traceback[2])とも言い、単にバックトレースとも言う[注釈 1]


注釈

  1. ^ GNUデバッガ (gdb) でのレポートコマンドは、バックトレース (backtrace) を縮めたbtである。GNUデバッガ#コマンド例も参照。
  2. ^ コールスタックの割り当てと解放は通例オペレーティングシステムが担当し、アプリケーションプログラムで明示的に割り当てと解放をする必要はない。

出典



「スタックトレース」の続きの解説一覧

「stack trace」の例文・使い方・用例・文例

Weblio日本語例文用例辞書はプログラムで機械的に例文を生成しているため、不適切な項目が含まれていることもあります。ご了承くださいませ。


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

辞書ショートカット

すべての辞書の索引

「stack trace」の関連用語

stack traceのお隣キーワード
検索ランキング

   

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



stack traceのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
IT用語辞典バイナリIT用語辞典バイナリ
Copyright © 2005-2024 Weblio 辞書 IT用語辞典バイナリさくいん。 この記事は、IT用語辞典バイナリスタックトレースの記事を利用しております。
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.
ウィキペディアウィキペディア
All text is available under the terms of the GNU Free Documentation License.
この記事は、ウィキペディアのスタックトレース (改訂履歴)の記事を複製、再配布したものにあたり、GNU Free Documentation Licenseというライセンスの下で提供されています。 Weblio辞書に掲載されているウィキペディアの記事も、全てGNU Free Documentation Licenseの元に提供されております。
Tanaka Corpusのコンテンツは、特に明示されている場合を除いて、次のライセンスに従います:
 Creative Commons Attribution (CC-BY) 2.0 France.
この対訳データはCreative Commons Attribution 3.0 Unportedでライセンスされています。
浜島書店 Catch a Wave
Copyright © 1995-2024 Hamajima Shoten, Publishers. All rights reserved.
株式会社ベネッセコーポレーション株式会社ベネッセコーポレーション
Copyright © Benesse Holdings, Inc. All rights reserved.
研究社研究社
Copyright (c) 1995-2024 Kenkyusha Co., Ltd. All rights reserved.
日本語WordNet日本語WordNet
日本語ワードネット1.1版 (C) 情報通信研究機構, 2009-2010 License All rights reserved.
WordNet 3.0 Copyright 2006 by Princeton University. All rights reserved. License
日外アソシエーツ株式会社日外アソシエーツ株式会社
Copyright (C) 1994- Nichigai Associates, Inc., All rights reserved.
「斎藤和英大辞典」斎藤秀三郎著、日外アソシエーツ辞書編集部編
EDRDGEDRDG
This page uses the JMdict dictionary files. These files are the property of the Electronic Dictionary Research and Development Group, and are used in conformance with the Group's licence.

©2024 GRAS Group, Inc.RSS