Question

My logcat window in Eclipse only displays the first few lines of the StackTrace for each exception. This means that I often can't see where an exception occured. Is there any way to change this setting?

Was it helpful?

Solution

If you're referring to the "...12 more lines..." part, you only see that for exceptions that were the cause of another exception. If the top part of the stack trace is the same as the earlier trace, the full set of frames is only shown for the outermost exception, and the other traces get the "..." treatment.

Put another way, the chunk of a trace that isn't shown is a duplicate of a trace that appeared earlier in the exception cause chain. For example, suppose I have code where the method main() calls one(), which calls two(), and so on. four() throws an exception. two() catches it and re-throws it. The exception will look like this:

java.lang.RuntimeException: re-throw
    at Foo.two(Foo.java:14)
    at Foo.one(Foo.java:7)
    at Foo.main(Foo.java:3)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: first
    at Foo.four(Foo.java:23)
    at Foo.three(Foo.java:19)
    at Foo.two(Foo.java:12)
    ... 3 more

The "caused by" exception says "... 3 more" rather than explicitly listing one(), main(), and dalvik.system.NativeStart.main. So to get the full trace of the initial exception, you would start by reading its trace, then continue at the trace above.

Note there is no overlap -- two() appears in both, but in the "first" trace it's on the call to three(), and in the "re-throw" trace it's on the throw instruction.

OTHER TIPS

you can overload all the log methods (log.d, log.i, log.e, etc) with (String tag, String msg, Throwable tr) parameters, where the third parameter is the exception. This will give you the full stacktrace in logcat

http://developer.android.com/reference/android/util/Log.html

If your code calls a method which produces too tall of stack you can (and should) handle the exception in your code and output whatever is relevant to logs.

If you have no exception handling whatsoever and you don't even know where in your code should you be putting such a handler then the problem is entirely elsewhere - you should be handling exceptions a bit better than that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top