简体   繁体   English

如何在Eclipse中显示完整的堆栈跟踪?

[英]How to show full stack trace on eclipse?

I'm using Eclipse to debug a Java application. 我正在使用Eclipse调试Java应用程序。 Somewhere in the code I get an exception and the stack trace: 在代码中的某个地方,我得到了异常和堆栈跟踪:

Caused by: java.io.EOFException: The connection has been reset while reading the header
    at com.gemstone.gemfire.internal.cache.tier.sockets.Message.fetchHeader(Message.java:583)
    at com.gemstone.gemfire.internal.cache.tier.sockets.Message.readHeaderAndPayload(Message.java:599)
    at com.gemstone.gemfire.internal.cache.tier.sockets.Message.read(Message.java:542)
    at com.gemstone.gemfire.internal.cache.tier.sockets.Message.recv(Message.java:1029)
    at com.gemstone.gemfire.cache.client.internal.AbstractOp.attemptReadResponse(AbstractOp.java:158)
    at com.gemstone.gemfire.cache.client.internal.AbstractOp.attempt(AbstractOp.java:363)
    at com.gemstone.gemfire.cache.client.internal.ConnectionImpl.execute(ConnectionImpl.java:229)
    at com.gemstone.gemfire.cache.client.internal.pooling.PooledConnection.execute(PooledConnection.java:321)
    at com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.executeWithPossibleReAuthentication(OpExecutorImpl.java:646)
    at com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.execute(OpExecutorImpl.java:108)
    ... 11 more

How do I get the whole stack instead of the ... 11 more ? 如何获得整个堆栈而不是其他... 11 more

You have the entire stack. 拥有整个堆栈。

This is only part of a stack trace. 这只是堆栈跟踪的一部分。 Directly before this was another piece. 紧接在此之前是另外一块。 Look at the bottom lines of this one, and the top lines of the previous one. 查看这一行的底线和上一行的顶线。 You'll see them match up. 您会看到它们匹配。 The stack trace began with a section that doesn't begin with "Caused by". 堆栈跟踪的开头不是以“ Caused by”开头的部分。

The "Caused by" exception is hiding parts of the stack trace that are verbatim copies of stack trace entries in its parent. “由...引起”异常将堆栈跟踪的某些部分隐藏为其父堆栈中堆栈跟踪条目的逐字副本。 In other words, Java doesn't show the entire stack up to main() for every cause - it just shows what you haven't seen already. 换句话说,Java不会针对每种原因在main()之前显示整个堆栈-它只是显示您尚未看到的内容。 See the Throwable.printStackTrace() documentation . 请参阅Throwable.printStackTrace()文档

The "Caused by" is filled when you provide a cause when creating a Throwable. 在创建Throwable时提供原因时,将填写“ Causeed by”。 Look at the constructors for it. 查看它的构造函数。 This is done when a piece of code catches a low-level exception and then wants to rethrow it as a different exception class. 当一段代码捕获到一个低级别的异常,然后又想将其作为另一个异常类重新抛出时,便可以完成此操作。

the answers above are not accurate, every time the stack show the words "caused by" it means that the exception went through one or multiple methods until it was caught, and then thrown again. 上面的答案并不准确,每次堆栈显示单词“ caused by”时,都意味着该异常经过一种或多种方法,直到被捕获,然后再次引发。 This could happen many many many times, the stack trace is not a loop, it is a single direction, so no, the stuff at the top does not relate to the stuff at the bottom, the most important part IS at the bottom, that is the root of the exception, so if you would have: 这可能会发生很多很多次,堆栈跟踪不是一个循环,而是一个方向,所以不,顶部的内容与底部的内容无关,最重要的部分是底部的内容,是异常的根源,因此如果您有:

Exception in class main: blah blah blah ...lines of code... caused by FileNotFoundException ...lines of code... caused by: MalformedURLException ...lines of code... caused by: NullPointerException 类main中的异常:等等等等...代码行...由FileNotFoundException引起...代码行...由...引起:MalformedURLException ...代码行...由...引起:NullPointerException

then you would not want to focus so much on the FileNotFoundException, but you would want to focus more on the NullPointerException. 那么您将不希望过多地关注FileNotFoundException,而是希望更多地关注NullPointerException。 Like say you had a properties file with a file name in it. 就像说您有一个属性文件,其中包含文件名。 If accidentally used mykey, to find the property "myKey", then the propertiesResource would return a null, that would then get thrown all the way through all the lines of code (hopefully) to your application where the last catch block is. 如果不小心使用了mykey来查找属性“ myKey”,则propertiesResource将返回null,然后将其抛出所有代码行(一直希望)一直到最后一个catch块所在的应用程序。 . . wich, at this piont, it would be "wrapped" not as a nullException, but as a FileNotFoundException. 在这种情况下,它不是作为nullException而是作为FileNotFoundException被“包装”。 . .

在此处输入图片说明

We might be diverging from the actual problem he's facing. 我们可能与他面临的实际问题有所分歧。 I was having similar problem and it turns out I had my Limit console out put box check marked. 我遇到了类似的问题,原来我的Limit console输出框已选中。 After I removed it I was able to see the full stack trace. 删除它后,我可以看到完整的堆栈跟踪。 Steps: Right click on console || 步骤:右键单击控制台||。 ctrl + click if mac go to preferences and follow the above instructions Ctrl +单击,如果Mac转到偏好设置并按照上述说明进行操作

I think it means that the Exception was caught and packaged into another 11 times before printStackTrace was called. 我认为这意味着在printStackTrace之前,该Exception已被捕获并打包到另外11次中。

Try and figure out the output of the following program for better understanding: 尝试找出以下程序的输出以更好地理解:

public class PrintStackTrace {

    public static void main(String[] args) {
        try {
            level1();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            level2();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    static void level2() throws Exception {
        try {
            level1();
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    static void level1() throws Exception {
        try {
            throwingMethod();
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    static void throwingMethod() throws Exception {
        throw new Exception("throwingMethod");
    }

}

As Ed says, it is showing the entire stack, but leaving out information that you've already seen. 正如Ed所言,它显示的是整个堆栈,但是遗漏了您已经看到的信息。 See Throwable#printStackTrace() 请参阅Throwable#printStackTrace()

Quoting from there: 从那里报价:

Note the presence of lines containing the characters "...". 请注意是否存在包含字符“ ...”的行。 These lines indicate that the remainder of the stack trace for this exception matches the indicated number of frames from the bottom of the stack trace of the exception that was caused by this exception (the "enclosing" exception). 这些行表明,此异常的堆栈跟踪的其余部分与由该异常(“封闭”异常)引起的异常的堆栈跟踪的底部指示的帧数匹配。 This shorthand can greatly reduce the length of the output in the common case where a wrapped exception is thrown from same method as the "causative exception" is caught 这种简写可以大大减少输出的长度,在通常情况下,捕获异常是通过与捕获“引起性异常”相同的方法引发的:

Often an exception is wrapped; 通常会包装一个例外; created with another exception as the cause: 创建的另一个异常是原因:

try {
    // something which causes an Exception
} catch (Exception e) {
    throw new SpecificException("help", e);
}

In this case, displaying the stacktrace will create the ... 11 more that you see. 在这种情况下,显示stacktrace将创建您看到的... 11。

I have never seen that, but try this 我从未见过,但是尝试一下

public void problemFunction(){
  try{
      //your code
  catch(Exception ex){
     ex.printStackTrace();
  }
}

or 要么

public void problemFunction(){
  try{
      //your code
     }
  catch(Exception ex){
     System.out.println(ex);
     StackTraceElement[] arr = ex.getStackTrace();
     for(int i=0; i<arr.length; i++){
       System.out.println(arr[i].toString());
     }
  }
}

There is a vmargs option 有一个vmargs选项

 -XX:-OmitStackTraceInFastThrow

which might help in some situations. 在某些情况下可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM