The perfect StackOverflow question has finally come....
How do I catch a StackOverflow exception!
It seems in .NET Core the StackOverflowException
isn't available:
And if I run this code:
using System;
namespace PlayGround.Core.Console
{
public class Program
{
public static void Main(string[] args)
{
try
{
DoSomething();
}
catch(Exception e)
{
System.Console.WriteLine("Bugger");
}
}
private static void DoSomething()
{
DoSomething();
}
}
}
I get this:
You can see my exception handler didn't run. So how do I go about catching this exception in .NET Core?
EDIT September 15th, 2017: In .NET Core 2.0 there is now a StackOverflowException class, but it still doesn't actually catch a stackoverflow exception.