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 CIL 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


StackOverflowException() Constructor

public StackOverflowException();

Summary

Constructs and initializes a new instance of the StackOverflowException class.

Description

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 .

See Also

System.StackOverflowException Class, System Namespace

StackOverflowException(System.String) Constructor

public StackOverflowException(string message);

Summary

Constructs and initializes a new instance of the StackOverflowException class.

Parameters

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.

Description

This constructor initializes the System.StackOverflowException.Message property of the new instance using message. If message is null , 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 to null .

See Also

System.StackOverflowException Class, System Namespace

StackOverflowException(System.String, System.Exception) Constructor

public StackOverflowException(string message, Exception innerException);

Summary

Constructs and initializes a new instance of the StackOverflowException class.

Parameters

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 .

Description

This constructor initializes the System.StackOverflowException.Message property of the new instance using message, and the System.StackOverflowException.InnerException property using innerException. If message is null , 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.]

See Also

System.StackOverflowException Class, System Namespace