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.
Using printStackTrace() method − It print the name of the exception, description and complete stack trace including the line where exception occurred. Using toString() method − It prints the name and description of the exception. Using getMessage() method − Mostly used. It prints the description of the exception.
In Java, there are three methods to print exception information. All of them are present in the Throwable class. Since Throwable is the base class for all exceptions and errors, we can use these three methods on any exception object.
Just use new Throwable(). printStackTrace() method and it will print complete stack trace from where a method is called, into the console.
The Throwable class provides the following three methods to print the exception message: Using printStackTrace Method. Using getMessage() Method. Using toString() Method.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With