NoClassDefFoundError, can I ignore that?
Guys, I know how why it occured.
But the thing is, what if I did it in purpose, so I can tell which method I should use?
Consider following sample
I've tried many possible way to get away from the Error.
The code compiled successfully but failed when runing because I removed the jar file that contain the KMException in purpose.
The reason why I am doing this it because there is a possibility that my Application may build with reference to a jar file. but the customer may not necessary to have this jar file.
Any idea?
public class Test{
Object t;
public Test ()
{
try
{
t = Class.forName("com.ibm.gsk.ikeyman.basic.KMException");
com.ibm.gsk.ikeyman.basic.KMException a = (com.ibm.gsk.ikeyman.basic.KMException)t;
b();
}
catch(ClassNotFoundException e)
{
t = new Exception();
c();
}
}
public void a() throws com.ibm.gsk.ikeyman.basic.KMException
{
System.out.println("a ");
}
public void b()
{
try
{
v();
}
catch(Exception e)
{
System.out.println("E ");
}
}
public static void main(String[] args){
Test a = new Test();
}
} // Test
[1305 byte] By [
ada1016] at [2007-9-26 6:40:34]

>can I ignore that?
Yes.
Exceptions can be generated under the following conditions:
-Totally unexpected
-Expected, with handling
-Expected, with no handling
An example using the OutOfMemory exception.
-Unexpected: I write a socket program to display something that occurs once a minute - a small amount of data. The application gets a OutOfMemory error once an hour. This means something is wrong with my code, bad things will occur if I continue.
-Expected, with handling: I write a graphics program that buffers previous images. If I get a OutOfMemory error I clear some of the older buffers and tell the user to try again.
-Expected, ignored: I write a program to see how many threads I can create before I get an OutOfMemory error. When I catch the OutOfMemory exception I print the total number of threads created and exit. I don't need to do anything with the exception itself.
Keep in mind that the above might be a little far fetched as an OutOfMemory exception might be caused by other things which I can't fix and could conceivably leave things in an unstable state, also which I can't fix.
But in your case you know exactly what you are doing. You can use one of two classes. And you use the not found exception to figure out which to use. So as long as the rest of your code follows this and you document what you are doing carefully (so the next guy understands it) there is no problem.
To Jschell,
Thanks for the detailed explanation..
But it seem to me that you are talking about exception handling. not ERROR handling..
I mean, so far as I know, I can't cacth Error, such as
NoClassDefFoundError,
you got any handy experience that catach this error? or avoid the error?
To smh3r.
Because of some copyright and user requirement. we were not allow the included the jar file. let say, A user doesn't want to see B.jar because B.jar is competitor to A. and unfortunately, our code couldn't get rid of B.jar yet. too much effort to do that.
>I can't cacth Error, such as
Yes you can. You catch checked and unchecked exceptions in the same way. You can either catch an explict error or just the general case
catch(Throwable e) ....
I always do this in my main and thread loops, so I can do printStackTraces.