Mono Class Library: System Namespace

System.StackOverflowException Class

Represents the error that occurs when the execution stack overflows due to too many method calls. [Edit]

See Also: StackOverflowException Members

System.Object
     System.Exception
          System.SystemException
               System.StackOverflowException

[System.Runtime.InteropServices.ComVisible(true)]
public sealed class StackOverflowException : SystemException

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Remarks

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.

[Edit]

Example

The following example demonstrates an error that causes a StackOverflowException exception.

C# Example
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.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0