ClassNotFoundException is thrown when a class is loaded. The class may be loaded well before your code ever gets control, because it is referred to from another class, which is referred to from another class, ...
A common cause of CNFE, in my experience, is that a static initializer throws an exception. We have a number of classes in our system that initialize static members using properties loaded from a resource file. If the property value is not set in the resource file (or if the resource file is missing), the intializer throws a "MissingResourceException", which is translated to a ClassNotFoundException or NoClassDefFoundError. Depending on the chain of "extends" and on which classes have static intializers, some of which may cause other classes to be loaded, the exception can be thrown even before your "main" is called.

What does your stack trace look like? Is it really ClassNotFoundException, or is it perhaps NoClassDefFoundError, which does not inherit from Exception? ClassNotFoundException, according to the documentation, is thrown only from the following methods:

* The |forName| method in class |Class|.
* The |findSystemClass| method in class |ClassLoader| .
* The |loadClass| method in class |ClassLoader|.

NoClassDefFoundError is thrown "if the Java Virtual Machine or a classloader tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the |new| expression) and no definition of the class could be found."

=Spencer

Greg Nudelman wrote:

Guys, I have a thread that throws a ClassNotFoundException, from the class loader. This causes the entire thread to die, right then and there, even though a wrapper method catches all java.lang.Exception, though that catch block there never gets executed. I think this should not occur -- bug in JVM? Your experiences?
Please share.
Greg
Solaris, JVM 1.3.1_06
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

Reply via email to