Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The simplest way to detect it will throw an Error is to wait until it throws and error and catch it.</p> <pre><code>try { action(); } catch(StackOverflowError ste) { // you can't call anything here safely, but you can return or unwind the stack. } </code></pre> <p>Note: the maximum stack size varies between machine and is based on command lines settings. It is not based on a number of calls.</p> <p>If you are really concerned about this issue, I suggest changing the code do it doesn't use recursion and you avoid this issue completely.</p> <hr> <p>The problem is that the maximum stack depth is displayed/recorded is 1024. If you have a longer stack, you won't see what caused it originally. What you can do is to <em>reduce</em> the maximum stack size with <code>-Xss128k</code> (or less if your JVM allows it) so that your stack traces will always be short enough to be captured.</p> <pre><code>public static void main(String... ignored) { callMe(1); } private static void callMe(int i) { callMe(i); } </code></pre> <p>when called with a smaller stack size</p> <pre><code>at Main.callMe(Main.java:42) at Main.callMe(Main.java:42) at Main.callMe(Main.java:42) many deleted at Main.callMe(Main.java:42) at Main.callMe(Main.java:42) at Main.callMe(Main.java:42) at Main.main(Main.java:38) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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