Have you guys ever seen an Exception stacktrace which looks like this:
Exception in thread "main" java.lang.Exception: some error happened
at SomeClass.method1(StackTraceExample.java:24)
at SomeClass.method2(SomeClass.java:20)
at SomeClass.method3(SomeClass.java:25)
at SomeClass.method4(SomeClass.java:20)
at SomeClass.method5(SomeClass.java:25)
...5 more
???
I see the above type of Exception printouts all the time, and have a few questions.
First, does "...5 more" mean that there are 5 more lines in the stack trace which are being suppressed in order to achieve some preset limit for how many lines may appear in a stacktrace printout? (Looking at the source code of Throwable did not answer this question, as the lowest level methods which get the stack trace are ultimately native calls.)
Second, is there any way to suppress this behavior (e.g. a java command line option) so that you always get the full stack trace printed out?
Incidentally, for this forum posting, I wrote the following test class to try to demo the effect of truncated stack traces:
public class StackTraceExample {
private static final int maxNumberOfCalls = 10;
private static int numberOfCalls = 0;
public static void main(String[] args) throws Exception {
foo();
}
private static void foo() throws Exception {
if (++numberOfCalls >= maxNumberOfCalls) throw new Exception("hit maximum recursion limit");
bar();
}
private static void bar() throws Exception {
if (++numberOfCalls >= maxNumberOfCalls) throw new Exception("hit maximum recursion limit");
foo();
}
}
However, whenever I run this class, no matter what value I assign the maxNumberOfCalls field, I never get a "...XXX more" line in my stack trace, instead I always see the full number of lines, so I am unable to duplicate that stack trace behavior for some reason. But I know that it occurs!