System.StackOverflowException Class
public sealed class StackOverflowException : SystemException
Base Types
Object
Exception
SystemException
StackOverflowException
Assembly
mscorlib
Library
BCL
Summary
Represents the error that occurs when the execution stack overflows due to too many method calls.
Description
[Note: StackOverflowException is thrown for execution stack overflow errors, typically in the case of a very deep or unbounded recursion.
The localloc IL instruction throws StackOverflowException.
]
Example
The following example demonstrates an error that causes a StackOverflowException exception.
using System;
public class StackOverflowExample {
public static void recursion() { recursion(); }
public static void Main() {
try {
recursion();
}
catch(StackOverflowException e) {
Console.WriteLine("Error caught: {0}", e);
}
}
}
The output is
Error caught: System.StackOverflowException: Exception of type System.StackOverflowException was thrown.
See Also
System Namespace
Members
StackOverflowException Constructors
StackOverflowException() Constructor
StackOverflowException(System.String) Constructor
StackOverflowException(System.String, System.Exception) Constructor