Home > Software > StackOverflowException.NET: catch me if you can

StackOverflowException.NET: catch me if you can


Here’s a quote from MSDN:

Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default.

Really? Why have the exception then anyway? So you can throw it yourself? And to be catch by whom?
I think that there are more graceful ways to end your process than throw new StackOverflowException ();

Consequently, users are advised to write their code to detect and prevent a stack overflow. For example, if your application depends on recursion, use a counter or a state condition to terminate the recursive loop.

I totally agree that StackOverflowException is the result of a serious problem in your application. But what happens if you cannot avoid recursion? You cannot control the stack size and how would you find out the value of such a counter?

Should you not have a graceful way of treating this, rather than having your process shut down?

I’m not a .Net expert, but I think this breaks the entire meaning of a managed runtime environment.

More info at http://msdn.microsoft.com/en-us/library/system.stackoverflowexception.aspx.

Categories: Software Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: