Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unreachable catch block for ClassNotFoundException

 
Prathik Ashok
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone can some one help me out here i am trying to develop this servlet for my jsp and when i try to deploy it using tomcat i get this error saying "Unreachable catch block for ClassNotFoundException. This exception is never thrown from the try statement body"


can some one help me figure this out or tell me what i am doing wrong ???

this is my code down below and the problem is at line 88

I am using Struts

basically what i have done is created an action class and a DAO which inserts the data into the tables I could fill up the data fields without the servlet but once i created the servlet i get that error

Regards

Prathik




this is my web.xml file




And this is what i get when i try to deploy it


SEVERE: Servlet.service() for servlet [candrep] in context with path [/project] threw exception [Servlet execution threw an exception] with root cause
java.lang.Error: Unresolved compilation problem:
Unreachable catch block for ClassNotFoundException. This exception is never thrown from the try statement body
 
Neeraj Dhiman
Ranch Hand
Posts: 68
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check curly braces in servlet.!!
 
Prathik Ashok
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neeraj Dhiman wrote:check curly braces in servlet.!!


I don't think that's the problem braces seem to be in order
 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ClassNotFoundException is a checked exception and your code is not throwing it anywhere explicitly. So compiler is telling you that this code will never be executed, Please remove that try and catch block as it is not required.
 
Prathik Ashok
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piyush Mangal wrote:ClassNotFoundException is a checked exception and your code is not throwing it anywhere explicitly. So compiler is telling you that this code will never be executed, Please remove that try and catch block as it is not required.


i removed the try and catch block but this is what i get when i try to deploy

Your FirstName is :null
Your Last Name is :null Your Contact Number is :null Your Contact Number is :null Your Contact Number is :null Your Email is :null Your Current Industry :null Your Current Industry :null Your Preferred Industry is :null Your Current Industry :null

and further more it inserts the querry into the database table


Insert Query formed: INSERT INTO candreppage4.posts(FirstName,LastName,Gender,Qualification,Email,ContactNumber,Industry,WorkExperience,PreferredIndustry,EmploymentStatus) VALUES('null','null','null','null','null','null','null','null','null','null')


 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does that have to do with try and catch block?
 
Prathik Ashok
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piyush Mangal wrote:What does that have to do with try and catch block?


well when i deploy it does not show me the required jsp and after i removed the try and catch block that's the result i got and it inserted a querry into the table
 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well when i deploy it does not show me the required jsp and after i removed the try and catch block that's the result i got and it inserted a querry into the table


And why do you think it should show you a required jsp? Where are you forwarding to a JSP page in your servlet? Where are you checking for null values in your servlet?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic