Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Unhandled Exception - please help!

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my code I have a method whereby I am trying to connect either to a local server or a mainframe (only this first if statement is shown) but in the BOLDED line below I am getting a "Unhandled exception type ClassNotFoundException". Any help or direction would be appreciated.

Here is my code:

 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class.forName throws ClassNotFoundException

So you need to catch it. Or have your method declare that it throws it.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

I guess what I don't understand is why I am getting this error. Before putting the if statement around this statement within the try catch I did not get this error. Is it only because I put it in an IF statement? This file is already in the classpath so I do not understand WHY this error now came up.

Any insight would be appreciated.

Thanks again.
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is more to it than the if statement. If you had the Class forName before then you must have made some other subtle change that gave it problems. Like you used to catch Exception and now you catch SQLException or you used to throws Exception in the method signature but now you only throw SQLException.

Something else changed. Class.forName throws ClassNotFoundException. It did before and it does now. So there was something else other than the if that meant that it wasn't a problem but now it is.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic