StackOverflowException Osztály
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Az a kivétel, amely akkor fordul elő, ha a végrehajtási verem meghaladja a verem méretét. Ez az osztály nem örökölhető.
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
- Öröklődés
- Attribútumok
Példák
Az alábbi példa egy számlálót használ annak biztosítására, hogy a metódushoz Execute irányuló rekurzív hívások száma ne haladja meg a MAX_RECURSIVE_CALLS állandó által meghatározott maximális értéket.
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
Megjegyzések
StackOverflowException a végrehajtási verem túlcsordulási hibái esetén történik, általában nagyon mély vagy kötetlen rekurzió esetén. Ezért győződjön meg arról, hogy a kód nem rendelkezik végtelen hurokkal vagy végtelen rekurzióval.
StackOverflowException A HRESULT COR_E_STACKOVERFLOW használja, amelynek értéke 0x800703E9. A Localloc köztes nyelv (IL) utasítás dob StackOverflowException. Az objektumok kezdeti tulajdonságértékeinek listájáért StackOverflowException tekintse meg a StackOverflowException konstruktorokat.
A blokkokkal try/catch nem lehet objektumot elkapniStackOverflowException, és a megfelelő folyamat alapértelmezés szerint le van állítva. Ezért meg kell írnia a kódot, hogy észlelje és megakadályozza a verem túlcsordulását. Ha például az alkalmazás a rekurziótól függ, használjon számlálót vagy állapotfeltételt a rekurzív hurok leállításához. A technika illusztrációját a Példák szakaszban találja.
Note
Ha az HandleProcessCorruptedStateExceptionsAttribute attribútumot egy olyan metódusra alkalmazza, amelynek StackOverflowException nincs hatása. Továbbra sem tudja kezelni a felhasználói kód kivételét.
Ha az alkalmazás üzemelteti a közös nyelvi futtatókörnyezetet (CLR), megadhatja, hogy a CLR-nek ki kell ürítenie azt az alkalmazástartományt, ahol a verem túlcsordulási kivétele történik, és hagyja, hogy a megfelelő folyamat folytatódjon. További információ: ICLRPolicyManager Interface.
Konstruktorok
| Name | Description |
|---|---|
| StackOverflowException() |
Inicializálja az StackOverflowException osztály új példányát, és az Message új példány tulajdonságát egy rendszer által megadott üzenetre állítja, amely leírja a hibát, például: "A kért művelet verem túlcsordulást okozott". Ez az üzenet figyelembe veszi a jelenlegi rendszerkultúrát. |
| StackOverflowException(String, Exception) |
Inicializálja az StackOverflowException osztály új példányát egy megadott hibaüzenettel és a kivétel okaként szolgáló belső kivételre mutató hivatkozással. |
| StackOverflowException(String) |
Inicializálja az StackOverflowException osztály új példányát egy megadott hibaüzenettel. |
Tulajdonságok
| Name | Description |
|---|---|
| Data |
Lekéri a kulcs-/érték párok gyűjteményét, amelyek további, felhasználó által definiált információkat biztosítanak a kivételről. (Öröklődés forrása Exception) |
| HelpLink |
Lekéri vagy beállítja a kivételhez társított súgófájlra mutató hivatkozást. (Öröklődés forrása Exception) |
| HResult |
Lekéri vagy beállítja a HRESULT-ot, egy kódolt numerikus értéket, amely egy adott kivételhez van hozzárendelve. (Öröklődés forrása Exception) |
| InnerException |
Lekéri az Exception aktuális kivételt okozó példányt. (Öröklődés forrása Exception) |
| Message |
Az aktuális kivételt leíró üzenet jelenik meg. (Öröklődés forrása Exception) |
| Source |
Lekéri vagy beállítja az alkalmazás vagy a hibát okozó objektum nevét. (Öröklődés forrása Exception) |
| StackTrace |
Lekéri a hívásverem közvetlen kereteinek sztringképét. (Öröklődés forrása Exception) |
| TargetSite |
Lekéri az aktuális kivételt okozó metódust. (Öröklődés forrása Exception) |
Metódusok
| Name | Description |
|---|---|
| Equals(Object) |
Meghatározza, hogy a megadott objektum egyenlő-e az aktuális objektummal. (Öröklődés forrása Object) |
| GetBaseException() |
Ha egy származtatott osztály felül van bírálva, egy Exception vagy több későbbi kivétel kiváltó okát adja vissza. (Öröklődés forrása Exception) |
| GetHashCode() |
Ez az alapértelmezett kivonatoló függvény. (Öröklődés forrása Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Ha felül van bírálva egy származtatott osztályban, a SerializationInfo kivétel adatait adja meg. (Öröklődés forrása Exception) |
| GetType() |
Lekéri az aktuális példány futtatókörnyezeti típusát. (Öröklődés forrása Exception) |
| MemberwiseClone() |
Az aktuális Objectpéldány sekély másolatát hozza létre. (Öröklődés forrása Object) |
| ToString() |
Létrehozza és visszaadja az aktuális kivétel sztring-ábrázolását. (Öröklődés forrása Exception) |
esemény
| Name | Description |
|---|---|
| SerializeObjectState |
Akkor fordul elő, ha a kivétel szerializálva van egy kivételállapot-objektum létrehozásához, amely szerializált adatokat tartalmaz a kivételről. (Öröklődés forrása Exception) |