StackTrace 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
하나 이상의 스택 프레임으로 이루어진 순서가 있는 집합인 스택 추적을 나타냅니다.
public ref class StackTrace sealed
public ref class StackTrace
public sealed class StackTrace
[System.Serializable]
public class StackTrace
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class StackTrace
public class StackTrace
type StackTrace = class
[<System.Serializable>]
type StackTrace = class
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type StackTrace = class
Public NotInheritable Class StackTrace
Public Class StackTrace
- 상속
-
StackTrace
- 특성
예제
다음 콘솔 애플리케이션은 간단 StackTrace 하게 만들고 프레임을 반복하여 디버깅 및 진단 정보를 가져오는 방법을 보여 줍니다.
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
*/
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
'
설명
StackTrace 정보는 디버그 빌드 구성에 가장 유용할 것입니다. 기본적으로 디버그 빌드에는 디버그 기호가 포함되지만 릴리스 빌드는 포함되지 않습니다. 디버그 기호에는 StackFrame 및 StackTrace 객체를 구성하는 데 사용되는 대부분의 파일, 메서드 이름, 줄 번호 및 열 정보가 포함됩니다.
StackTrace 최적화 중에 발생하는 코드 변환으로 인해 메서드 호출이 예상대로 많이 보고되지 않을 수 있습니다.
생성자
| Name | Description |
|---|---|
| StackTrace() |
호출자의 프레임에서 클래스의 StackTrace 새 인스턴스를 초기화합니다. |
| StackTrace(Boolean) |
필요에 따라 원본 정보를 캡처하여 호출자의 프레임에서 클래스의 새 인스턴스 StackTrace 를 초기화합니다. |
| StackTrace(Exception, Boolean) |
제공된 예외 개체를 사용하고 필요에 따라 원본 정보를 캡처하여 클래스의 StackTrace 새 인스턴스를 초기화합니다. |
| StackTrace(Exception, Int32, Boolean) |
지정된 프레임 수를 건너뛰고 필요에 따라 원본 정보를 캡처하여 제공된 예외 개체를 사용하여 클래스의 새 인스턴스 StackTrace 를 초기화합니다. |
| StackTrace(Exception, Int32) |
제공된 예외 개체를 사용하여 지정된 수의 StackTrace 프레임을 건너뛰어 클래스의 새 인스턴스를 초기화합니다. |
| StackTrace(Exception) |
제공된 예외 개체를 사용하여 클래스의 StackTrace 새 인스턴스를 초기화합니다. |
| StackTrace(Int32, Boolean) |
지정된 프레임 수를 건너뛰고 필요에 따라 원본 정보를 캡처하여 호출자의 프레임에서 클래스의 새 인스턴스 StackTrace 를 초기화합니다. |
| StackTrace(Int32) |
지정된 프레임 수를 건너뛰고 호출자의 프레임에서 클래스의 새 인스턴스 StackTrace 를 초기화합니다. |
| StackTrace(StackFrame) |
단일 프레임을 포함하는 클래스의 StackTrace 새 인스턴스를 초기화합니다. |
| StackTrace(Thread, Boolean) |
사용되지 않음.
필요에 따라 원본 정보를 캡처하여 특정 스레드에 대한 클래스의 StackTrace 새 인스턴스를 초기화합니다. 이 생성자 오버로드를 사용하지 마세요. |
필드
| Name | Description |
|---|---|
| METHODS_TO_SKIP |
스택 추적에서 생략할 메서드 수의 기본값을 정의합니다. 이 필드는 상수입니다. |
속성
| Name | Description |
|---|---|
| FrameCount |
스택 추적의 프레임 수를 가져옵니다. |
메서드
| Name | Description |
|---|---|
| Equals(Object) |
지정한 개체와 현재 개체가 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
| GetFrame(Int32) |
지정된 스택 프레임을 가져옵니다. |
| GetFrames() |
현재 스택 추적에 있는 모든 스택 프레임의 복사본을 반환합니다. |
| GetHashCode() |
기본 해시 함수로 작동합니다. (다음에서 상속됨 Object) |
| GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| ToString() |
스택 추적의 읽기 가능한 표현을 빌드합니다. |