stack overflow - Odd Java StackOverflowError? -


why code totally destroy output?

public class main {     public static void main(string[] args) {         system.out.println();          rec();     }      private static int rec() {         try {             return rec();         } catch(stackoverflowerror e) {             system.out.println("boo.");             return 0;         }     } } 

sample output get: boo.boo.boo.boo.boo.boo.boo.boo.boo.

the problem similar problem in question: stack overflow error handling in block

basically, println call handler stackoverflowexception triggering further stackoverflowexception. being handled in enclosing call rec(). continues (unwinding rec() calls go) until exception handler has enough space complete println call. intermediate calls adding characters output buffer, , raising soe.

a precise explanation require forensic analysis of code of printstream , stream stack ... way point calls native code.


if want meta-explanation, code attempting recover error ... javadocs should not attempt do. general rule, after error, jvm going uncertain, , possibly broken state. in case, uncertainty manifests data may or may not have been written buffer. behaviour (probably) deterministic, hard analyse , impossible predict without proper analysis.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -