StackOverflowException Sınıf
Tanım
Çok fazla iç içe geçmiş yöntem çağrısı içerdiğinden, yürütme yığını taştığında oluşturulan özel durum.The exception that is thrown when the execution stack overflows because it contains too many nested method calls. Bu sınıf devralınamaz.This class cannot be inherited.
public ref class StackOverflowException sealed : SystemException
public sealed class StackOverflowException : SystemException
[System.Serializable]
public sealed class StackOverflowException : SystemException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class StackOverflowException : SystemException
type StackOverflowException = class
inherit SystemException
[<System.Serializable>]
type StackOverflowException = class
inherit SystemException
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type StackOverflowException = class
inherit SystemException
Public NotInheritable Class StackOverflowException
Inherits SystemException
- Devralma
- Öznitelikler
Örnekler
Aşağıdaki örnek, yöntemine yapılan özyinelemeli çağrıların sayısının Execute MAX_RECURSIVE_CALLS sabiti tarafından tanımlanan bir üst sınırı aşmadığından emin olmak için bir sayaç kullanır.The following example uses a counter to ensure that the number of recursive calls to the Execute method do not exceed a maximum defined by the MAX_RECURSIVE_CALLS constant.
using System;
public class Example
{
private const int MAX_RECURSIVE_CALLS = 1000;
static int ctr = 0;
public static void Main()
{
Example ex = new Example();
ex.Execute();
Console.WriteLine("\nThe call counter: {0}", ctr);
}
private void Execute()
{
ctr++;
if (ctr % 50 == 0)
Console.WriteLine("Call number {0} to the Execute method", ctr);
if (ctr <= MAX_RECURSIVE_CALLS)
Execute();
ctr--;
}
}
// The example displays the following output:
// Call number 50 to the Execute method
// Call number 100 to the Execute method
// Call number 150 to the Execute method
// Call number 200 to the Execute method
// Call number 250 to the Execute method
// Call number 300 to the Execute method
// Call number 350 to the Execute method
// Call number 400 to the Execute method
// Call number 450 to the Execute method
// Call number 500 to the Execute method
// Call number 550 to the Execute method
// Call number 600 to the Execute method
// Call number 650 to the Execute method
// Call number 700 to the Execute method
// Call number 750 to the Execute method
// Call number 800 to the Execute method
// Call number 850 to the Execute method
// Call number 900 to the Execute method
// Call number 950 to the Execute method
// Call number 1000 to the Execute method
//
// The call counter: 0
Module Example
Private Const MAX_RECURSIVE_CALLS As Integer = 1000
Dim ctr As Integer = 0
Public Sub Main()
Execute()
Console.WriteLine()
Console.WriteLine("The call counter: {0}", ctr)
End Sub
Private Sub Execute()
ctr += 1
If ctr Mod 50 = 0 Then
Console.WriteLine("Call number {0} to the Execute method", ctr)
End If
If ctr <= MAX_RECURSIVE_CALLS Then
Execute()
End If
ctr -= 1
End Sub
End Module
' The example displays the following output:
' Call number 50 to the Execute method
' Call number 100 to the Execute method
' Call number 150 to the Execute method
' Call number 200 to the Execute method
' Call number 250 to the Execute method
' Call number 300 to the Execute method
' Call number 350 to the Execute method
' Call number 400 to the Execute method
' Call number 450 to the Execute method
' Call number 500 to the Execute method
' Call number 550 to the Execute method
' Call number 600 to the Execute method
' Call number 650 to the Execute method
' Call number 700 to the Execute method
' Call number 750 to the Execute method
' Call number 800 to the Execute method
' Call number 850 to the Execute method
' Call number 900 to the Execute method
' Call number 950 to the Execute method
' Call number 1000 to the Execute method
'
' The call counter: 0
Açıklamalar
StackOverflowException , genellikle çok derin veya sınırsız özyineleme durumunda, yürütme yığını taşma hataları için oluşturulur.StackOverflowException is thrown for execution stack overflow errors, typically in case of a very deep or unbounded recursion. Bu nedenle, kodunuzun sonsuz bir döngüye veya sonsuz özyineleme içermediğinden emin olun.So make sure your code doesn't have an infinite loop or infinite recursion.
StackOverflowException 0x800703E9 değeri olan HRESULT COR_E_STACKOVERFLOW kullanır.StackOverflowException uses the HRESULT COR_E_STACKOVERFLOW, which has the value 0x800703E9. LocallocAra dil (IL) yönergesi atar StackOverflowException .The Localloc intermediate language (IL) instruction throws StackOverflowException. Bir nesnenin ilk özellik değerlerinin listesi için StackOverflowException bkz StackOverflowException . oluşturucular.For a list of initial property values for a StackOverflowException object, see the StackOverflowException constructors.
.NET Framework 2,0 ' den başlayarak, StackOverflowException bir nesneyi try / catch bloklarla yakalayamaz ve ilgili işlem varsayılan olarak sonlandırılır.Starting with the .NET Framework 2.0, you can't catch a StackOverflowException object with a try/catch block, and the corresponding process is terminated by default. Sonuç olarak, bir yığın taşmasını tespit etmek ve engellemek için kodunuzu yazmanız gerekir.Consequently, you should write your code to detect and prevent a stack overflow. Örneğin, uygulamanız özyinelemeye bağımlıysa özyinelemeli döngüyü sonlandırmak için bir sayaç veya durum koşulu kullanın.For example, if your app depends on recursion, use a counter or a state condition to terminate the recursive loop.
Bu tekniğin çizimi için örnekler bölümüne bakın.See the Examples section for an illustration of this technique.
Not
HandleProcessCorruptedStateExceptionsAttributeÖzniteliğini oluşturan bir metoda özniteliği uygulamak StackOverflowException hiçbir etkiye sahip değildir.Applying the HandleProcessCorruptedStateExceptionsAttribute attribute to a method that throws a StackOverflowException has no effect. Hala kullanıcı kodundan özel durumu işleyemezsiniz.You still cannot handle the exception from user code.
Uygulamanız ortak dil çalışma zamanını (CLR) barındırıyorsa, CLR 'nin yığın taşması özel durumunun gerçekleştiği uygulama etki alanını yüklemesini ve ilgili işlemin devam etmesini sağlayabilirsiniz.If your app hosts the common language runtime (CLR), it can specify that the CLR should unload the application domain where the stack overflow exception occurs and let the corresponding process continue. Daha fazla bilgi için bkz. ICLRPolicyManager arabirimi.For more information, see ICLRPolicyManager Interface.
Oluşturucular
| StackOverflowException() |
Sınıfının yeni bir örneğini başlatır StackOverflowException ve Message "istenen işlem yığın taşmasına neden oldu" gibi, hatayı açıklayan sistem tarafından sağlanan bir ileti olarak yeni Örneğin özelliğini ayarlar.Initializes a new instance of the StackOverflowException class, setting the Message property of the new instance to a system-supplied message that describes the error, such as "The requested operation caused a stack overflow." Bu ileti, geçerli sistem kültürünü göz önünde bulundurur.This message takes into account the current system culture. |
| StackOverflowException(String) |
Belirtilen bir hata iletisiyle sınıfın yeni bir örneğini başlatır StackOverflowException .Initializes a new instance of the StackOverflowException class with a specified error message. |
| StackOverflowException(String, Exception) |
StackOverflowExceptionBelirtilen bir hata iletisiyle sınıfın yeni bir örneğini ve bu özel durumun nedeni olan iç özel duruma bir başvuruyu başlatır.Initializes a new instance of the StackOverflowException class with a specified error message and a reference to the inner exception that is the cause of this exception. |
Özellikler
| Data |
Özel durum hakkında ek kullanıcı tanımlı bilgiler sağlayan anahtar/değer çiftleri koleksiyonunu alır.Gets a collection of key/value pairs that provide additional user-defined information about the exception. (Devralındığı yer: Exception) |
| HelpLink |
Bu özel durumla ilişkili Yardım dosyasının bağlantısını alır veya ayarlar.Gets or sets a link to the help file associated with this exception. (Devralındığı yer: Exception) |
| HResult |
Belirli bir özel duruma atanan kodlanmış bir sayısal değer olan HRESULT 'yi alır veya ayarlar.Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception. (Devralındığı yer: Exception) |
| InnerException |
ExceptionGeçerli özel duruma neden olan örneği alır.Gets the Exception instance that caused the current exception. (Devralındığı yer: Exception) |
| Message |
Geçerli özel durumu açıklayan bir ileti alır.Gets a message that describes the current exception. (Devralındığı yer: Exception) |
| Source |
Uygulamanın veya hataya neden olan nesnenin adını alır veya ayarlar.Gets or sets the name of the application or the object that causes the error. (Devralındığı yer: Exception) |
| StackTrace |
Çağrı yığınında anlık çerçevelerin dize gösterimini alır.Gets a string representation of the immediate frames on the call stack. (Devralındığı yer: Exception) |
| TargetSite |
Geçerli özel durumu oluşturan yöntemi alır.Gets the method that throws the current exception. (Devralındığı yer: Exception) |
Yöntemler
| Equals(Object) |
Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.Determines whether the specified object is equal to the current object. (Devralındığı yer: Object) |
| GetBaseException() |
Türetilmiş bir sınıfta geçersiz kılınırsa, Exception bir veya daha fazla sonraki özel durumun kök nedeni olan öğesini döndürür.When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions. (Devralındığı yer: Exception) |
| GetHashCode() |
Varsayılan karma işlevi olarak işlev görür.Serves as the default hash function. (Devralındığı yer: Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Türetilmiş bir sınıfta geçersiz kılınırsa, SerializationInfo özel durum hakkındaki bilgileri ayarlar.When overridden in a derived class, sets the SerializationInfo with information about the exception. (Devralındığı yer: Exception) |
| GetType() |
Geçerli örneğin çalışma zamanı türünü alır.Gets the runtime type of the current instance. (Devralındığı yer: Exception) |
| MemberwiseClone() |
Geçerli bir basit kopyasını oluşturur Object .Creates a shallow copy of the current Object. (Devralındığı yer: Object) |
| ToString() |
Geçerli özel durumun dize gösterimini oluşturur ve döndürür.Creates and returns a string representation of the current exception. (Devralındığı yer: Exception) |
Ekinlikler
| SerializeObjectState |
Özel durum hakkında serileştirilmiş veri içeren bir özel durum nesnesi oluşturmak için bir özel durum serileştirildiğinde gerçekleşir.Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception. (Devralındığı yer: Exception) |