I'm trying to catch a number from a Scanner. I thought that I could catch the InputMismatchException and re-ask the user to submit another real number.
I use this but if I raise the exception it keeps in an infinite loop:
Joined: Oct 13, 2005
Because of the exception, the done variable remains false for ever. The Scanner continues to look at the token which wasn't a number, so consume that token with a call to in.next(); inside the catch. No need to do anything with that token.
Then you can enter a new token, and the loop can go round once more.