14

I've noticed that whenever an exception is thrown on the terminal, I often get an abbreviate failure trace such as this:

java.lang.NoClassDefFoundError: javafx/application/Application
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more
Exception in thread "main" 

What I want to know is how to print all of the trace, including those ... 13 more.

EDIT: This post has been identified as a possible duplicate of Print full call stack on printStackTrace()? . I did read the latter but didn't find an answer to my question, I only found information on why it happens.

Community
  • 1
  • 1
Maslor
  • 1,821
  • 3
  • 20
  • 44
  • Actually.. it will print entier thing .. what is stopping here is your console... Increase your console's page lines (or make it unlimited), then you will get enterire list – Pavan Kumar K Jul 24 '15 at 10:08
  • 4
    duplicate: http://stackoverflow.com/questions/1043378/print-full-call-stack-on-printstacktrace – chengpohi Jul 24 '15 at 10:09
  • And how can I implement those changes to my console @PavanKumarK? I'm using win7, by the way, perhaps it's relevant to the question. – Maslor Jul 24 '15 at 10:10
  • Why do you want to see 13 more, when they are already present in the printed lines? – Dragan Bozanovic Jul 24 '15 at 10:28

4 Answers4

4

You can pass the Throwable object (the Exception in your case) to a method like this:

static void printFullTrace(Throwable throwable){
    for(StackTraceElement element: throwable())
        System.out.println(element);
}

The truth is that you are already seeing the whole stack trace in those lines, because a part of it is repeated and so omitted for brevity. You can understand better the mechanism here.

Community
  • 1
  • 1
enrico.bacis
  • 30,497
  • 10
  • 86
  • 115
  • Although this is indeed quite useful information, what I am looking for, if it even exists, is a simple way to make my command line print all the trace, instead of writing "...13 more" @PavanKumarK said in the comments that you could increase your console's page lines but hasn't developed his answer yet... Is it possible? – Maslor Jul 24 '15 at 10:15
  • @Maslor: I have added it – enrico.bacis Jul 24 '15 at 10:34
  • Thanks for the clarification! – Maslor Jul 24 '15 at 10:44
0
StackTraceElement[] stackTraces = Thread.currentThread().getStackTrace();
for (StackTraceElement element : stackTraces) {
    System.out.println(element);
}
enrico.bacis
  • 30,497
  • 10
  • 86
  • 115
Recoba20
  • 314
  • 1
  • 13
  • I'm looking for an alternative simple method that doesn't require adding code to my application, if it exists. – Maslor Jul 24 '15 at 10:25
  • http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#getStackTrace() is that enough, or I am missing something that you know, but do not want to share ? – Recoba20 Jul 24 '15 at 13:12
0

You can print the whole stack Traces by below method. Reading the Java Doc for printStackTrace will tell why is this designed this way.

void printAllTraces(Throwable throwable) {
       StackTraceElement[] stackTraces = throwable.getStackTrace();
       for (StackTraceElement stackTrace: stackTraces) {
          System.out.println(stackTrace); 
       }
}
sakthisundar
  • 3,278
  • 3
  • 16
  • 29
  • I'm looking for an alternative simple method that doesn't require adding code to my application, if it exists. – Maslor Jul 24 '15 at 10:25
  • 1
    printStackTrace can give only this much and this is designed in order to be concise. So without adding little code I am afraid there is no way you get the full stack trace. – sakthisundar Jul 24 '15 at 10:28
-1

The standard Windows console (cmd) is very short of features, you need to install a console on steroids like ones that are out there, so you'll be able to have a larger scrollback. Take a look into the alternatives listed here.

Personally I use cmder, that is not in the list, but you must test them all and peek which fit you better.

enrico.bacis
  • 30,497
  • 10
  • 86
  • 115
Eduardo Yáñez Parareda
  • 9,126
  • 4
  • 37
  • 50