how to reproduce the stack overflow exception in c# code example
Example: exception handling c# stack overflow
class Program
{
static int n;
static int topOfStack;
const int stackSize = 1000000;
const int spaceRequired = 18*1024;
unsafe static void Main(string[] args)
{
int var;
topOfStack = (int)&var;
n=0;
recurse();
}
unsafe static void recurse()
{
int remaining;
remaining = stackSize - (topOfStack - (int)&remaining);
if (remaining < spaceRequired)
throw new Exception("Cheese");
n++;
recurse();
}
}