wood burning stoves 2.0
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
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
Rancher

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: 20080
    
  30

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: InputMismatchException not working?
 
It's not a secret anymore!