StackTrace Sınıf
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Bir veya daha fazla yığın çerçevesinin sıralı bir koleksiyonu olan bir yığın izlemesi temsil eder.
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
- Devralma
-
StackTrace
- Öznitelikler
Örnekler
Aşağıdaki konsol uygulaması, hata ayıklama ve tanılama bilgilerini almak için basit StackTrace bir oluşturma ve çerçeveleri arasında yineleme yapmayı gösterir.
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
'
Açıklamalar
StackTrace bilgiler, Hata ayıklama derleme yapılandırmaları ile en bilgilendirici olacaktır. Varsayılan olarak, Hata ayıklama derlemeleri hata ayıklama sembolleri içerir, ancak Yayın derlemeleri içermez. Hata ayıklama sembolleri, ve nesneleri oluştururken StackFrameStackTrace kullanılan dosya, yöntem adı, satır numarası ve sütun bilgilerinin çoğunu içerir.
StackTrace en iyi duruma getirme sırasında gerçekleşen kod dönüştürmeleri nedeniyle beklendiği kadar çok yöntem çağrısı raporlamayabilir.
Oluşturucular
| Name | Description |
|---|---|
| StackTrace() |
Çağıranın çerçevesinden StackTrace sınıfının yeni bir örneğini başlatır. |
| StackTrace(Boolean) |
İsteğe bağlı olarak kaynak bilgileri yakalayarak çağıranın çerçevesinden sınıfının yeni bir örneğini StackTrace başlatır. |
| StackTrace(Exception, Boolean) |
Sağlanan özel durum nesnesini kullanarak ve isteğe bağlı olarak kaynak bilgileri yakalayarak sınıfının yeni bir örneğini StackTrace başlatır. |
| StackTrace(Exception, Int32, Boolean) |
Sağlanan özel durum nesnesini kullanarak sınıfın StackTrace yeni bir örneğini başlatır, belirtilen sayıda kare atlar ve isteğe bağlı olarak kaynak bilgileri yakalar. |
| StackTrace(Exception, Int32) |
Sağlanan özel durum nesnesini kullanarak sınıfın StackTrace yeni bir örneğini başlatır ve belirtilen sayıda kareyi atlar. |
| StackTrace(Exception) |
Sağlanan özel durum nesnesini kullanarak sınıfının yeni bir örneğini StackTrace başlatır. |
| StackTrace(Int32, Boolean) |
Çağıranın çerçevesinden StackTrace sınıfın yeni bir örneğini başlatır, belirtilen sayıda kare atlar ve isteğe bağlı olarak kaynak bilgileri yakalar. |
| StackTrace(Int32) |
Çağıranın çerçevesinden sınıfın StackTrace yeni bir örneğini başlatır ve belirtilen kare sayısını atlar. |
| StackTrace(StackFrame) |
Sınıfının tek bir çerçeve içeren yeni bir örneğini StackTrace başlatır. |
| StackTrace(Thread, Boolean) |
Geçersiz.
İsteğe bağlı olarak kaynak bilgileri yakalayarak belirli bir iş parçacığı için sınıfının yeni bir örneğini StackTrace başlatır. Bu oluşturucu aşırı yükleme kullanmayın. |
Alanlar
| Name | Description |
|---|---|
| METHODS_TO_SKIP |
Yığın izlemesinden atlanacak yöntem sayısı için varsayılan değeri tanımlar. Bu alan sabittir. |
Özellikler
| Name | Description |
|---|---|
| FrameCount |
Yığın izlemesindeki çerçeve sayısını alır. |
Yöntemler
| Name | Description |
|---|---|
| Equals(Object) |
Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler. (Devralındığı yer: Object) |
| GetFrame(Int32) |
Belirtilen yığın çerçevesini alır. |
| GetFrames() |
Geçerli yığın izlemesindeki tüm yığın çerçevelerinin bir kopyasını döndürür. |
| GetHashCode() |
Varsayılan karma işlevi işlevi görür. (Devralındığı yer: Object) |
| GetType() |
Geçerli örneğin Type alır. (Devralındığı yer: Object) |
| MemberwiseClone() |
Geçerli Objectbasit bir kopyasını oluşturur. (Devralındığı yer: Object) |
| ToString() |
Yığın izlemesinin okunabilir bir gösterimini oluşturur. |