StackGoBoom.java

Download StackGoBoom.java

 1: // This class shows what happens when you overflow the stack.
 2: // The "try" block prevents the system from generating a run-time
 3: // stack trace when the program aborts.
 4: //
 5: // To make the crash happen sooner, add some large local variables to
 6: // the recurse method, to make each stack frame (activation record)
 7: // larger.
 8: //
 9: // Written 2004 by Wayne Pollock, Tampa Florida USA.
10: 
11: class StackGoBoom
12: {
13:     public static void main ( String [] args )
14:     {
15:         try
16:         {
17:             recurse( 1 );
18:         }
19:         catch ( Throwable t ) { System.out.println( t ); }
20:     }
21: 
22:     static void recurse ( int level )
23:     {
24:         System.out.println( level );
25:         recurse( level + 1 );
26:     }
27: }