呼び出し元のフレームから 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。
例外
例外の種類 | 条件 |
---|---|
skipFrames パラメータが負の値です。 |
解説
インスタンスの作成時に、スキップするフレームの数がコール スタック上のフレームの合計数以上の場合は、StackTrace にフレームは含まれません。
使用例
さまざまな 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
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0