I've written a super simple java class that is throwing exceptions as it should. However the stack trace I'm getting looks like this:
java.lang.RuntimeException: hello at Main.go(Unknown Source) at Main.main(Unknown Source)
Note: there are no line numbers in the stack trace and I would like there to be.
The answers you find when googling this problem are all about adding the correct parameters at compile time to make sure the line numbers actually make it into the class file. However, I don't believe that's my problem as I have this in my ant build.xml
<javac debug="true" debuglevel="lines,vars,source" includeAntRuntime="false" classpathref="classpath.compile" srcdir="${src.dir}" destdir="${build.classes}" />
Also, according to javap, it looks like the line numbers did make it in:
$ javap -l ./build/classes/Main | head -n 9 public class Main extends java.lang.Object{ public Main(); LineNumberTable: line 14: 0 line 22: 4 line 23: 15 line 24: 26
So what gives? Is there a param I need to set in the jvm when I run the code?
Thanks!
…it means that the program lacks the relevant debugging information. Specifically the class files are missing the LineNumberTable attribute (JVMS 4.7. 12).
To read this stack trace, start at the top with the Exception's type - ArithmeticException and message The denominator must not be zero . This gives an idea of what went wrong, but to discover what code caused the Exception, skip down the stack trace looking for something in the package com.
Simply put, a stack trace is a representation of a call stack at a certain point in time, with each element representing a method invocation. The stack trace contains all invocations from the start of a thread until the point it's generated. This is usually a position at which an exception takes place.
A trace of the method calls is called a stack trace. The stack trace listing provides a way to follow the call stack to the line number in the method where the exception occurs. The StackTrace property returns the frames of the call stack that originate at the location where the exception was thrown.
I think the correct way is:
<javac debug="true" debuglevel="lines,vars,source"
Note there are no spaces between lines,vars,source
Found this answer on another question:
This is normally related to missing debug information. You are probably using JRE (not JDK), which does not include debug information for rt.jar classes. Try using full JDK, you'll get proper locations in the stack trace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With