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:
- calls
doit()again - 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
Post a Comment