Why isn't the code trying to catch the StackOverflowError being triggered?

This question extends from this stackoverflow question .

If I add a catch block, why do the catch block codes never run?

public static void foo() {
    try {
        foo();
    } catch(StackOverflowError e) {       
       System.exit(1); // or System.err.println("ouch!"); whatever
    } finally {
        foo();
    }
}

      

I am referring to JLS Chapter 11.1.3 - Asynchronous exceptions - is this the reason why the catch blocking reason has no chance to run?

+3
java stack-overflow recursion try-finally


source to share


No one has answered this question yet

See similar questions:

319
Try-finally block prevents StackOverflowError

or similar:

1722
Why is this code using random lines to print "hello world"?
1215
Why is Java code executed in comments with some Unicode characters?
877
Why doesn't RecyclerView have onItemClickListener ()?
378
Why shouldn't I wrap each block in "try" - "catch"?
319
Try-finally block prevents StackOverflowError
43
How does Java System.exit () work with try / catch / finally blocks?
6
Calling call return or System.exit in try or catch block
4
Why is my static block of code not executing?
1
Problems accessing and running code in try catch blocks
0
Java exception - why is it catching?



All Articles
Loading...
X
Show
Funny
Dev
Pics