Quote:
Originally Posted by knc1
@ixtab: Isn't Java one of those languages where the interface (definition) and the implementation can be in two different files (here, only one of the required two).
It has been a long time since I Java'd -
One would probably be called an "abstract class" and the "class implementation".
Hence two similar error messages, depending on which of the two can not be found.
|
Yeah, but that's called "interface"/"abstract class", and I hope that I know the difference.
The thing that I don't understand is why directly referencing an inexistent class gives a ClassNotFoundException (all fine until here), but trying to load an (existing) class which has a reference to an inexistent class gives a "NoSuchClassDefError". The problem is exactly the same - a required class isn't found, so why not throw the same exception?
Answering my own question: it's probably due to an
idiosyncrasy of the JVM, namely the difference between checked and unchecked exceptions. In short: trying to load a named class can throw a (checked=must be caught) "ClassNotFoundException". But if that class is actually found, but isn't "initializable" because it itself depends on another non-found class, that produces an unchecked exception, namely "NoClassDefFoundError". Go figure.