This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 19654
    
  18

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?
 
Similar Threads
Initial variables before a try\catch block
Problem with PrintWriter and another Problem with Inputhandling
Looping in exceptions
Problem in looping
try...catch blocks giving <identifier> expected error