This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes InputMismatchException not working? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "InputMismatchException not working?" Watch "InputMismatchException not working?" New topic
Author

InputMismatchException not working?

Jake Cirino
Greenhorn

Joined: Jul 27, 2012
Posts: 17

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
Bartender

Joined: May 31, 2011
Posts: 1776
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

Joined: Oct 27, 2005
Posts: 19684
    
  20

You shouldn't catch an InputMismatchException, you should prevent it:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: InputMismatchException not working?