I have the following code. After compilation I delete the MyClassToLoad.class file and run the code.
public class ClassLoadersTest {
public static void main(String[] args) {
MyClassToLoad c = new MyClassToLoad();
}
}
I get the following stacktrace:
Exception in thread "main" java.lang.NoClassDefFoundError: classloaders/MyClassToLoad at classloaders.ClassLoadersTest.main(ClassLoadersTest.java:9) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: classloaders.MyClassToLoad at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:303) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
... 6 more
As far as I understand, this stacktrace means that there was a ClassNotFoundException, that was caught and rethrown as a NoClassDefFoundError.
The questions are:
1) How can I understand at which line the rethrow happened?
2) Who cuts the stacktrace with "... 6 more" - Java or Idea? How can I see it full?
3) As far as I understand to force the rethrown exception contain the full stacktrace we need to rethrow it as
throw new SomeRethrownException("some text", exceptionWhichIsTheReason)
But the NoClassDefFoundError doesn't have such a constructor. So in fact it shouldn't print the full stacktrace.. or may be they just put it as Error message as a String?