Catch StackOverflowException for recursive function : Function Definition « Language Basics « C# / C Sharp






Catch StackOverflowException for recursive function




using System;
   
class MainClass
{
    public static void Main()
    {
        try
        {
            Recursive();
        }
        catch(StackOverflowException)
        {
            Console.WriteLine("The CLR is out of stack space.");
        }
    }
   
    public static void Recursive()
    {
        Recursive();
    }
}

           
       








Related examples in the same category

1.Recursive sum methodRecursive sum method
2.Use a recursive method, travel, to journey from start to finishUse a recursive method, travel, to journey from start to finish
3.Recursive Factorial method.
4.Recursive function in actionRecursive function in action
5.Define functionDefine function