StackOverflowException Klas
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
De uitzondering die wordt gegenereerd wanneer de uitvoeringsstack groter is dan de stackgrootte. Deze klasse kan niet worden overgenomen.
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
- Overname
- Kenmerken
Voorbeelden
In het volgende voorbeeld wordt een teller gebruikt om ervoor te zorgen dat het aantal recursieve aanroepen naar de Execute methode niet hoger is dan een maximum dat is gedefinieerd door de MAX_RECURSIVE_CALLS constante.
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
Opmerkingen
StackOverflowException wordt gegenereerd voor overloopfouten van de uitvoeringsstack, meestal in het geval van een zeer diepe of niet-gebonden recursie. Zorg er dus voor dat uw code geen oneindige lus of oneindige recursie heeft.
StackOverflowException maakt gebruik van de HRESULT-COR_E_STACKOVERFLOW, met de waarde 0x800703E9. De Localloc tussenliggende taal (IL) instructie werpt StackOverflowException. Zie de StackOverflowException constructors voor een lijst met initiële eigenschapswaarden voor een StackOverflowException object.
U kunt een StackOverflowException object niet met een try/catch blok vangen en het bijbehorende proces wordt standaard beëindigd. Daarom moet u uw code schrijven om een stack-overloop te detecteren en te voorkomen. Als uw app bijvoorbeeld afhankelijk is van recursie, gebruikt u een teller of een statusvoorwaarde om de recursieve lus te beëindigen. Zie de sectie Voorbeelden voor een afbeelding van deze techniek.
Note
HandleProcessCorruptedStateExceptionsAttribute Het kenmerk toepassen op een methode die een StackOverflowException effect veroorzaakt, heeft geen effect. U kunt de uitzondering van gebruikerscode nog steeds niet verwerken.
Als uw app als host fungeert voor de Common Language Runtime (CLR), kan deze opgeven dat de CLR het toepassingsdomein moet verwijderen waarin de stack-overloop-uitzondering optreedt en het bijbehorende proces moet voortzetten. Zie ICLRPolicyManager Interface voor meer informatie.
Constructors
| Name | Description |
|---|---|
| StackOverflowException() |
Initialiseert een nieuw exemplaar van de StackOverflowException klasse, waarbij de Message eigenschap van het nieuwe exemplaar wordt ingesteld op een door het systeem opgegeven bericht waarin de fout wordt beschreven, zoals 'De aangevraagde bewerking heeft een stack-overloop veroorzaakt'. Dit bericht houdt rekening met de huidige systeemcultuur. |
| StackOverflowException(String, Exception) |
Initialiseert een nieuw exemplaar van de StackOverflowException klasse met een opgegeven foutbericht en een verwijzing naar de binnenste uitzondering die de oorzaak van deze uitzondering is. |
| StackOverflowException(String) |
Initialiseert een nieuw exemplaar van de StackOverflowException klasse met een opgegeven foutbericht. |
Eigenschappen
| Name | Description |
|---|---|
| Data |
Hiermee haalt u een verzameling sleutel-waardeparen op die aanvullende door de gebruiker gedefinieerde informatie over de uitzondering bieden. (Overgenomen van Exception) |
| HelpLink |
Hiermee haalt u een koppeling op naar het Help-bestand dat aan deze uitzondering is gekoppeld. (Overgenomen van Exception) |
| HResult |
Hiermee wordt HRESULT opgehaald of ingesteld, een gecodeerde numerieke waarde die is toegewezen aan een specifieke uitzondering. (Overgenomen van Exception) |
| InnerException |
Hiermee haalt u het Exception exemplaar op dat de huidige uitzondering heeft veroorzaakt. (Overgenomen van Exception) |
| Message |
Hiermee wordt een bericht weergegeven waarin de huidige uitzondering wordt beschreven. (Overgenomen van Exception) |
| Source |
Hiermee wordt de naam van de toepassing of het object dat de fout veroorzaakt, opgehaald of ingesteld. (Overgenomen van Exception) |
| StackTrace |
Hiermee haalt u een tekenreeksweergave van de directe frames op de aanroepstack op. (Overgenomen van Exception) |
| TargetSite |
Hiermee haalt u de methode op waarmee de huidige uitzondering wordt gegenereerd. (Overgenomen van Exception) |
Methoden
| Name | Description |
|---|---|
| Equals(Object) |
Bepaalt of het opgegeven object gelijk is aan het huidige object. (Overgenomen van Object) |
| GetBaseException() |
Wanneer deze wordt overschreven in een afgeleide klasse, retourneert u de Exception hoofdoorzaak van een of meer volgende uitzonderingen. (Overgenomen van Exception) |
| GetHashCode() |
Fungeert als de standaardhashfunctie. (Overgenomen van Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Wanneer deze wordt overschreven in een afgeleide klasse, stelt u de SerializationInfo met informatie over de uitzondering in. (Overgenomen van Exception) |
| GetType() |
Hiermee haalt u het runtimetype van het huidige exemplaar op. (Overgenomen van Exception) |
| MemberwiseClone() |
Hiermee maakt u een ondiepe kopie van de huidige Object. (Overgenomen van Object) |
| ToString() |
Hiermee maakt en retourneert u een tekenreeksweergave van de huidige uitzondering. (Overgenomen van Exception) |
gebeurtenis
| Name | Description |
|---|---|
| SerializeObjectState |
Treedt op wanneer een uitzondering wordt geserialiseerd om een uitzonderingsstatusobject te maken dat geserialiseerde gegevens over de uitzondering bevat. (Overgenomen van Exception) |