The Summation (16-Summation.exe) sample application shown later in this chapter demonstrates how to use exception filters and exception handlers to recover gracefully from a stack overflow. The source code and resource files for the application are in the 16-Summation directory on the companion content Web page. You might want to review the chapters on SEH to fully understand how this application works.
The Summation application sums all the numbers from 0 through
x is a number entered by the user. Of course, the simplest way to do this is to create a function called
Sum that simply performs the following calculation:
Sum = (x * (x + 1)) / 2;
However, for this sample, I have written the
Sum function to be ...