How to avoid the 1024 lines of Java exception stack limit

前端 未结 3 692
暗喜
暗喜 2020-12-18 20:08

I ran into a Java StackOverflow error, but the offending recursive call is so deep, that it does not give me the full stack trace. It only dumps out the first 1024 lines of

相关标签:
3条回答
  • 2020-12-18 20:29

    You can use -Xss to change the stack size, but it won't help if you have unbounded recursion. It sounds like your stopping condition might not be worked out.

    0 讨论(0)
  • 2020-12-18 20:29

    Print the stack manually, the limit put on e.printStackTrace() does not apply when you provide a writer (might need to quote me on that but I've never experienced it being cropped when using this method).

    Here is some easy code that I employ to get full traces:

    /**
     * Produces a Java-like stack trace string.
     * 
     * @param e
     * @return
     */
    public static String exceptionStack(Throwable e) {
        final Writer result = new StringWriter();
        final PrintWriter printWriter = new PrintWriter(result);
        e.printStackTrace(printWriter);
        return result.toString();
    }
    
    0 讨论(0)
  • 2020-12-18 20:39

    The switch -XX:MaxJavaStackTraceDepth allows larger and smaller stack trace lengths. Set it to -1 for an unlimited length. E.g.:

    -XX:MaxJavaStackTraceDepth=-1
    
    0 讨论(0)
提交回复
热议问题