Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to produce a StackOverflowException with a few lines of code?

How can I produce a StackOverflowException with minimal lines of code?

like image 900
aGuy Avatar asked Dec 17 '10 16:12

aGuy


People also ask

How do I handle StackOverflowException?

Starting with the . NET Framework 2.0, you can't catch a StackOverflowException object with a try / catch block, and the corresponding process is terminated by default. Consequently, you should write your code to detect and prevent a stack overflow.

What causes StackOverflowException?

StackOverflowError is a runtime error which points to serious problems that cannot be caught by an application. The java. lang. StackOverflowError indicates that the application stack is exhausted and is usually caused by deep or infinite recursion.


2 Answers

throw new StackOverflowException();

Cheating, I know... :)

like image 89
BoltClock Avatar answered Oct 27 '22 05:10

BoltClock


Like this:

A() { new A(); }
like image 37
SLaks Avatar answered Oct 27 '22 04:10

SLaks