开发者

How to show full stack trace on eclipse?

I'm using Eclipse to debug a Java application. 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开发者_JAVA技巧 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?


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".

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. See the Throwable.printStackTrace() documentation.

The "Caused by" is filled when you provide a cause when creating a Throwable. 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. 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

then you would not want to focus so much on the FileNotFoundException, but you would want to focus more on the 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. . . wich, at this piont, it would be "wrapped" not as a nullException, but as a FileNotFoundException. . .


How to show full stack trace on eclipse?

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. 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


I think it means that the Exception was caught and packaged into another 11 times before printStackTrace was called.

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. See 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.


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

 -XX:-OmitStackTraceInFastThrow

which might help in some situations.


To simplify the accepted answer let us consider a simple notation.

    Exception in main ……           
    At A                                              
    At B                                 
    At C                        
                        
    Caused by ….                                    
    AT P                                    
    At Q                              
    AT R                               
    AT A    - >  { THIS ONE IS REPEATED ,  But slightly with line 
    number changes   }                  .
    MISSING 2 MORE  { THOSE 2 ARE NOTHING BUT B AND C .}

    Caused by …                          
    At X                               
    At Y                                
    At P     - >  { THIS ONE IS REPEATED ,  But slightly line 
    number changes   } 
    Missing 5 More ( Those 5 are nothing but Q,R, ,A,B,C ) 

Hence you have the entire stack.

But MAKE SURE CHECK BOX FOR “limit console output” is NOT checked under run/debug drop down --> console in eclipse preferences.

You can use the following code to get more clarity.

    try {
    // code causing exception 
    }
    
    catch(Exception ex){                        
        Throwable exThrowable=ex;
        
        while(exThrowable!=null) {
            System.out.println(exThrowable);
            StackTraceElement[] arr = 
             exThrowable.getStackTrace();
             for(int i=0; i<arr.length; i++){
               System.out.println(arr[i].toString());
             }
             exThrowable=exThrowable.getCause();
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜