I like the example found here:
HighLevelException: MidLevelException: LowLevelException
at Junk.a(Junk.java:13)
at Junk.main(Junk.java:4)
Caused by: MidLevelException: LowLevelException
at Junk.c(Junk.java:23)
at Junk.b(Junk.java:17)
at Junk.a(Junk.java:11)
... 1 more
Caused by: LowLevelException
at Junk.e(Junk.java:30)
at Junk.d(Junk.java:27)
at Junk.c(Junk.java:21)
... 3 more
Basically in the source code, main
calls function a
which calls function b
which calls ... which calls function e
.
Function e
throws a LowLevelException
which causes function c to catch the LowLevelException
and throw a MidLevelException
(wrapping the LowLevelException
instance inside of the MidLevelException
instance. The Exception
class has a constructor that is capable of taking in a different exception, wrapping it). This causes function a to catch the MidLevelException
and throw a HighLevelException
which now wraps the previous two Exception
instances.
As noted in the other answers, the stack trace isn't really truncated, you are seeing the full stack trace. The .. .3 more
in my example is there because it would be redundant otherwise. If you wanted to be redundant and waste output lines, .. 3 more
could be substituted with
at Junk.b(Junk.java:17)
at Junk.a(Junk.java:11)
at Junk.main(Junk.java:4)
But there is no need to output these three lines, because they are already implied.