“未知来源"在java堆栈跟踪中,但行号在类文件中 [英] "Unknown Source" in java stack trace, yet line numbers are in the class file

查看:29
本文介绍了“未知来源"在java堆栈跟踪中,但行号在类文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个超级简单的java类,它应该抛出异常.但是,我得到的堆栈跟踪如下所示:

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)

注意:堆栈跟踪中没有行号,我希望有.

你在谷歌搜索这个问题时找到的答案都是关于在编译时添加正确的参数以确保行号实际进入类文件.但是,我不相信这是我的问题,因为我的 ant build.xml 中有这个

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}" />

此外,根据 javap,看起来行号确实在:

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

那是什么?运行代码时是否需要在 jvm 中设置参数?

So what gives? Is there a param I need to set in the jvm when I run the code?

谢谢!

推荐答案

我认为正确的做法是:

<javac debug="true" debuglevel="lines,vars,source"

注意行、变量、源代码之间没有空格

这篇关于“未知来源"在java堆栈跟踪中,但行号在类文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆