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(); } }