长Java'try'块中的哪一行抛出异常?

Tim*_*lis 2 java eclipse debugging exception

有没有办法找出try块中哪一行抛出异常?

我正在研究Eclipse中的Java,看起来像

try {

  //Lots of code. Seriously. Lots.

} catch (Exception e){
  throw new OtherException();
}
Run Code Online (Sandbox Code Playgroud)

我在try块中遇到异常(然后被捕获).我如何弄清楚它被扔出去的地方?

问题

  • 堆栈跟踪仅显示OtherException的catch块中的行
  • 删除try/catch块并不简单,因为有许多异常被声明为thrown,需要捕获这些异常才能编译代码.

感觉应该有一种直截了当的方式来做到这一点.

注意:我没有写这段代码;-)

rle*_*ndi 13

使用cause参数Exceptions(见这里):

try {

  //Lots of code. Seriously. Lots.

} catch (Exception e){
  throw new OtherException(e); // Trick is here
}
Run Code Online (Sandbox Code Playgroud)

这样你cause也可以在stacktrace中获得异常.