English 中文(简体)
在长爪哇的哪个线 尝试区块 扔出一个例外?
原标题:Which line in a long Java try block is throwing an exception?

有没有办法找出 试管区里哪条线是破例?

我在日圆的爪哇工作 看起来像

try {

  //Lots of code. Seriously. Lots.

} catch (Exception e){
  throw new OtherException();
}

我在试管区碰到一个例外,(然后被抓住的)我如何找出它从何而来?

问题、问题、问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题、 问题

  • The stack trace only shows the line in the catch block for the OtherException
  • Removing the try/catch block isn t straightforward, as there are many exceptions declared as thrown which are required to be caught in order for the code to compile.

似乎应该有一种直截了当的方法来做到这一点。

注:我没有写此代码;-)

最佳回答
问题回答

您可以使用 throw new otherExpeption(e); 。作为文件 解释,这个构建者 构建了一个与指定原因 < em> 的新例外。

在 Eclipse 中, 您可以设置一个例外触发的断点 。 见 < a href=" http://help. eclipsse.org/helios/index.jsp?potic=/ org. eclipse.jdt.doc. user/ reference/views/breadpoints/ref- addexion_viewaction.htm" rel =“ nofolved” > Add Java Exception brepoint 。

对于这个特定案例, 您需要确保“ 被捕获的例外的缓期执行” 被选中 。

剪贴板破入调试器后, 你就会有很多工具可供使用。 您可以看到调用堆, 就可以检查变量等 。

只要打印堆叠跟踪或按调试模式运行

e.printStackTrace()

在丢弃时在 其它例外 构建器中传递 e 中的例外 。 它会为您提供全部的堆放踪迹, 并给出投放例外的线条 :

catch (Exception e) {
    throw new OtherException(e);
}

如果 其它例外 没有使用 例外 throwable 的构建器, 您可以做到 :

catch (Exception e) {
    OtherException o = new OtherException();
    o.initCause(e);
    throw o;
}

您也可以尝试将错误消息打印到控制台 : System.out.println( e. getMessage () );

中断点非常有用,因为你可以通过代码追踪 并精确地看它何时到达捕捉区块。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...