Your code fills up the stack, then once the stack is full it hits the catch statement. After that the rest of the code continues to fire... each of those error messages is a recursive call that was made. Your code is working as you programmed it.
If you want an example of recursion that does stuff before and after, and has an exit condition, the following should work as an example for you (with print statements to clarify what is happening on the stack).
Example:
public class RecurseExample {
public static void main(String[] args) {
System.out.println("hi");
doIt(1);
System.out.println("bye");
}
private static void doIt(int i){
if (i <= 3){
System.out.println("i before: " + i);
doIt(++i);
System.out.println("i after: " + i);
} else {
System.out.println("this is where the recursion stops and the execution will continue to unravel the stack");
}
}
}
The output:
hi
i before: 1
i before: 2
i before: 3
this is where the recursion stops and the execution will continue to unravel the stack
i after: 4
i after: 3
i after: 2
bye