recursion - Java dealing with stackoverflow and continue normal execution after stackoverflow error -


i'm trying recursion in java. want stop recursion , continue normal prgram execution

void doit(){     try{         doit();     }     catch (stackoverflowerror e) {         return;     }     system.out.println("error"); }   statement1 doit() statementcontinue 

i want program continue execution statementcontinue after stackoverflow error

your program doing told to.

each time call doit(), it:

  1. calls doit() again
  2. after finishes, prints error.

when stack overflow happens, innermost call finishes (because of return), , continues executing function called (like other function call).
called popping call stack.

the calling function (which doit()) executes next line (system.out.println("error");), returns its calling function, doit().
cycle repeats until stack popped – until gets tothe function called doit().


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -