Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Incomplete Exception stacktraces

843829Aug 26 2005 — edited Nov 9 2005
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!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 7 2005
Added on Aug 26 2005
5 comments
550 views