StackOverflowException Sınıf

Tanım

Yürütme yığını yığın boyutunu aştığında oluşan özel durum. Bu sınıf devralınamaz.

public ref class StackOverflowException sealed : SystemException
[System.Serializable]
public sealed class StackOverflowException : SystemException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class StackOverflowException : SystemException
public sealed class StackOverflowException : SystemException
[<System.Serializable>]
type StackOverflowException = class
    inherit SystemException
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type StackOverflowException = class
    inherit SystemException
type StackOverflowException = class
    inherit SystemException
Public NotInheritable Class StackOverflowException
Inherits SystemException
Devralma
StackOverflowException
Öznitelikler

Örnekler

Aşağıdaki örnekte, yönteme yapılan özyinelemeli çağrı sayısının MAX_RECURSIVE_CALLS sabiti tarafından tanımlanan üst sınırı aşmadığından emin olmak için Execute bir sayaç kullanılır.

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
let MAX_RECURSIVE_CALLS = 1000
let mutable ctr = 0
   
let rec execute () =
    ctr <- ctr + 1
    if ctr % 50 = 0 then
        printfn $"Call number {ctr} to the Execute method"
        
    if ctr <= MAX_RECURSIVE_CALLS then
        execute ()
        
    ctr <- ctr - 1
    
execute ()
printfn $"\nThe call counter: {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 ilişkisiz özyineleme durumunda yürütme yığını taşması hataları için oluşturulur. Bu nedenle kodunuzun sonsuz döngüye veya sonsuz özyinelemeye sahip olmadığından emin olun.

StackOverflowException değeri 0x800703E9 olan HRESULT COR_E_STACKOVERFLOW kullanır. Ara Localloc dil (IL) yönergesi oluşturur StackOverflowException. Bir StackOverflowException nesnenin ilk özellik değerlerinin listesi için oluşturuculara StackOverflowException bakın.

Bloğu olan try/catch bir StackOverflowException nesneyi yakalayamazsınız ve karşılık gelen işlem varsayılan olarak sonlandırılır. Sonuç olarak, yığın taşmasını algılamak ve önlemek için kodunuzu yazmanız gerekir. Örneğin, uygulamanız özyinelemeye bağlıysa özyinelemeli döngünün sonlandırılması için bir sayaç veya durum koşulu kullanın. Bu tekniğin çizimi için Örnekler bölümüne bakın.

Note

özniteliğini HandleProcessCorruptedStateExceptionsAttribute oluşturan bir yönteme StackOverflowException uygulamanın hiçbir etkisi yoktur. Özel durumu yine de kullanıcı kodundan işleyemezsiniz.

Uygulamanız ortak dil çalışma zamanını (CLR) barındırıyorsa, CLR'nin yığın taşması özel durumunun oluştuğu uygulama etki alanını kaldırması ve ilgili işlemin devam etmesine izin vermesi gerektiğini belirtebilir. Daha fazla bilgi için bkz. ICLRPolicyManager Arabirimi.

Oluşturucular

Name Description
StackOverflowException()

Yeni örneğin özelliğini "İstenen işlem yığın taşmasına neden oldu" gibi hatayı açıklayan sistem tarafından sağlanan bir iletiye ayarlayarak StackOverflowException sınıfının yeni bir örneğini Message başlatır. Bu ileti geçerli sistem kültürünü dikkate alır.

StackOverflowException(String, Exception)

Belirtilen bir hata iletisi ve bu özel durumun nedeni olan iç özel duruma başvuru ile StackOverflowException sınıfının yeni bir örneğini başlatır.

StackOverflowException(String)

Belirtilen bir hata iletisiyle sınıfının yeni bir örneğini StackOverflowException başlatır.

Özellikler

Name Description
Data

Özel durum hakkında kullanıcı tanımlı ek bilgiler sağlayan anahtar/değer çiftleri koleksiyonunu alır.

(Devralındığı yer: Exception)
HelpLink

Bu özel durumla ilişkili yardım dosyasının bağlantısını alır veya ayarlar.

(Devralındığı yer: Exception)
HResult

Belirli bir özel duruma atanan kodlanmış sayısal bir değer olan HRESULT değerini alır veya ayarlar.

(Devralındığı yer: Exception)
InnerException

Geçerli özel duruma neden olan Exception örneğini alır.

(Devralındığı yer: Exception)
Message

Geçerli özel durumu açıklayan bir ileti alır.

(Devralındığı yer: Exception)
Source

Hataya neden olan uygulamanın veya nesnenin adını alır veya ayarlar.

(Devralındığı yer: Exception)
StackTrace

Çağrı yığınındaki anlık çerçevelerin dize gösterimini alır.

(Devralındığı yer: Exception)
TargetSite

Geçerli özel durumu oluşturan yöntemini alır.

(Devralındığı yer: Exception)

Yöntemler

Name Description
Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetBaseException()

Türetilmiş bir sınıfta geçersiz kılındığında, sonraki bir veya daha fazla özel durumun kök nedeni olan Exception döndürür.

(Devralındığı yer: Exception)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetObjectData(SerializationInfo, StreamingContext)

Türetilmiş bir sınıfta geçersiz kılındığında, özel durumla ilgili bilgilerle SerializationInfo ayarlar.

(Devralındığı yer: Exception)
GetType()

Geçerli örneğin çalışma zamanı türünü alır.

(Devralındığı yer: Exception)
MemberwiseClone()

Geçerli Objectbasit bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli özel durumun dize gösterimini oluşturur ve döndürür.

(Devralındığı yer: Exception)

Ekinlikler

Name Description
SerializeObjectState

Özel durum hakkında serileştirilmiş veriler içeren bir özel durum durumu nesnesi oluşturmak için bir özel durum seri hale getirildiğinde gerçekleşir.

(Devralındığı yer: Exception)

Şunlara uygulanır

Ayrıca bkz.