Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Try, Catch Error  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am trying to write a catch, try block to ask user to enter number between 1-5 and if number outside these values it would provide error and ask user to input again. The problem this is not correct I get error "missing return statement" any help? thanks
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Walk through the code in your head - take all possible branches - does each path return an int?
 
Sheriff
Posts: 12192
199
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, the statement that could cause a NumberFormatException to be thrown should be inside the try block. You have it outside right now.
 
James Newby
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thanks so done this now and it seem to compile without problems
 
Junilu Lacar
Sheriff
Posts: 12192
199
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

James Newbie wrote:ok thanks so done this now and it seem to compile without problems


It may compile but I doubt that it works the way it should. Why did you move the while statement inside the try block? The statement that can throw a NumberFormatException is the parsing of a string to an integer value but I don't see that in your new code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!