Note that there are some explanatory texts on larger screens.

plurals
  1. POConfusing output from infinite recursion within try-catch
    text
    copied!<p>Consider the following code.</p> <pre class="lang-java prettyprint-override"><code>public class Action { private static int i=1; public static void main(String[] args) { try{ System.out.println(i); i++; main(args); }catch (StackOverflowError e){ System.out.println(i); i++; main(args); } } } </code></pre> <p>I am getting i value up to <code>4338</code> correctly. After catching the <code>StackOverflowError</code> output getting wired as follows.</p> <pre class="lang-java prettyprint-override"><code>4336 4337 4338 // up to this point out put can understand 433943394339 // 4339 repeating thrice 434043404340 4341 434243424342 434343434343 4344 4345 434643464346 434743474347 4348 434943494349 435043504350 </code></pre> <p>Consider <a href="http://ideone.com/rqX0jv" rel="nofollow">Live</a> demo here. It is working correctly up to <code>i=4330</code>. Actually how this happen? </p> <p><strong><em>FYI:</em></strong></p> <p>I did following code to realize what is happening here.</p> <pre class="lang-java prettyprint-override"><code>public class Action { private static int i = 1; private static BufferedWriter bw; static { try { bw = new BufferedWriter(new FileWriter("D:\\sample.txt")); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) throws IOException { bw.append(String.valueOf(i)+" "); try { i++; main(args); } catch (StackOverflowError e) { bw.append(String.valueOf(i)+" "); i++; main(args); } } } </code></pre> <p>Now previous issue not there. now value of <code>i</code> up to <code>16824744</code> correct and and runs further. I am hopping this may runs up to value of <code>i=2,147,483,647</code>(max value of int) without an issue.</p> <p>There is some issue with <code>println()</code>. There are similar answers bellow too. But why? </p> <p>What will be the actual reason?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload