This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

InputMismatchException not working?

 
Jake Cirino
Greenhorn
Posts: 17
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's my code, I wan't the user to enter integers only but this code doesn't seem to be working.



The error is at about line 30.
 
John Jai
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to catch the Exception, then you have to surround the code that takes the Scanner input. Below is the code that reads the input. You have misplaced your try-catch block.

 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't catch an InputMismatchException, you should prevent it:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic