StackOverflowException

Besides the heap memory, there’s another finite resource in an application: its stack used to keep track of local variables, method calls, and evaluation of expressions. When this resource gets exhausted, a StackOverflowException results. Again, this is one of the exception types that’s uncatchable because properly dealing with such a circumstance is far from trivial. (You shouldn’t cause any further stack usage doing so.)

Typically, a StackOverflowException indicates an unbounded recursive algorithm in your code (which is a bug) or the fact you’re processing “deep” recursive data structures. Let’s take a look at a few examples:

void BlowUp() {    BlowUp();}

Depending on the amount of state kept for every frame on the call ...

Get C# 4.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.