public sealed class StackOverflowException : SystemException
Object
Exception
SystemException
StackOverflowException
mscorlib
BCL
Represents the error that occurs when the execution stack overflows due to too many method calls.
[Note: StackOverflowException is thrown for execution stack overflow errors, typically in the case of a very deep or unbounded recursion.The localloc CIL instruction throws StackOverflowException.
]
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.
System Namespace
StackOverflowException Constructors
StackOverflowException() Constructor
StackOverflowException(System.String) Constructor
StackOverflowException(System.String, System.Exception) Constructor
public StackOverflowException();
Constructs and initializes a new instance of the StackOverflowException class.
This constructor initializes the System.StackOverflowException.Message property of the new instance to a system-supplied message that describes the error, such as "The requested operation caused a stack overflow." This message takes into account the current system culture.The System.StackOverflowException.InnerException property is initialized to
null
.
System.StackOverflowException Class, System Namespace
public StackOverflowException(string message);
Constructs and initializes a new instance of the StackOverflowException class.
- message
- A String that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
This constructor initializes the System.StackOverflowException.Message property of the new instance using message. If message isnull
, the System.StackOverflowException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments. The System.StackOverflowException.InnerException property is initialized tonull
.
System.StackOverflowException Class, System Namespace
public StackOverflowException(string message, Exception innerException);
Constructs and initializes a new instance of the StackOverflowException class.
- message
- A String that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
- innerException
- An instance of Exception that is the cause of the current Exception. If innerException is non-null, then the current Exception was raised in a catch block handling innerException .
This constructor initializes the System.StackOverflowException.Message property of the new instance using message, and the System.StackOverflowException.InnerException property using innerException. If message isnull
, the System.StackOverflowException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.[Note: For information on inner exceptions, see System.Exception.InnerException.]
System.StackOverflowException Class, System Namespace