There is this code:
public class Main {
public static void main(final String[] args) throws Exception {
System.out.print(\"1\");
doAnythi
Well the no. of times the stack overflow error is hit is undefined. However, the JVM allows you to recover from StackOverflowError
error and continue execution of the system normally.
It is proved by the following code:
public class Really {
public static void main(final String[] args) throws Exception {
System.out.print("1");
doAnything();
System.out.println("2");
}
private static void doAnything() {
try {
throw new StackOverflowError();
//doAnything();
}
catch(final Error e){
System.out.print("y");
}
}
}
Note however, as @Javier said, the StackOverflowError
is thrown by the JVM synchronously or asynchronously(which means it can be thrown by another thread, possibly a native thread) which is why it is not possible to get the stack trace of the error. The no. of times the thread(s) hit the catch()
block is undefined.