r/java • u/davidalayachew • Sep 20 '26
Stacktraces have such a weird ordering to them
Let's assume that my main() method represents index 1, and the actual failing method that is throwing the exception represents index 10.
Why on earth are exception stack traces printed like this?!
message for 4
4
3
2
1
message for 7
7
6
5
4
message for 10
10
9
8
7
Ignoring the fact that I have to mentally rearrange the stack trace elements into the right order, the actual error I care about is all the way at the bottom!
Why don't you just do it like this instead?
message for 10
10
9
8
message for 7
7
6
5
message for 4
4
3
2
1
- The cause of this entire stack trace is at the top, where it should be.
- The stack trace elements unravel very intuitively -- from the source of the problem down to the original caller.
- No more redundant entries of
4and7.- Look at the original stack trace -- there are 2 entries of
4and7, presumably to help you piece the jigsaw-puzzle that is your stack trace back together again lol.
- Look at the original stack trace -- there are 2 entries of
20
Upvotes
View all comments
Show parent comment
4
u/faxity Sep 20 '26
When using Intellij if you're pasting a trace from a logging app or something, you can go to code -> analyze stack trace and paste it in there. It'll show your project classes in blue (as you typically see in the console when running an app). Seeing the blue lines makes it easy to ingest and easy to ignore framework/lib lines from the trace, as you can quickly click through to the lines.