IndexOutOfBoundsException的代码中包含行号的详细信息

问题描述 投票:-1回答:1

我正在尝试获取IndexOutOfBounds Exception详细信息的更多细节,其中包括程序中的行号(基本上显示异常发生的位置)。我得到以下异常,但很难找到确切的发生在哪里。试过以下:

try{
   //something
}catch(IndexOutOfBoundsException ex){
   log.debug(ex.getMessage+ex.toString); // and some others 
}

但我只是收到一条消息:

Index: 0, Size: 0java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

但没有提供进一步的细节。我想知道异常发生在哪里。任何帮助表示赞赏。

java exception indexoutofboundsexception
1个回答
0
投票

“where”和“我们如何到达那里”包含在异常的堆栈跟踪中。

如果log是一些标准的日志记录框架,它可能会有一个像debug(String, Throwable)这样的签名版本,能够打印堆栈跟踪/位置信息。

否则,你必须使用printStackTrace()或通过getStackTrace()访问你需要的堆栈跟踪元素。

© www.soinside.com 2019 - 2024. All rights reserved.