From http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#nextInt%28int%29 :
"If the translation is successful, the scanner advances past the input that matched."
Ah, but what if the translation is not successful? In that case, the scanner does not advance past any input. The bad input data remains as the next thing to be scanned, so the next iteration of the loop will fail just like the previous one--the loop will keep trying to read the same bad input over and over.
To prevent an infinite loop, you have to advance past the bad data so that you can get to something the scanner can read as an integer. The code snippet below does this by calling input.next():
Scanner input = new Scanner(System.in);
while(true){
try {
int choice = input.nextInt();
System.out.println("Input was " + choice);
} catch (InputMismatchException e){
String bad_input = input.next();
System.out.println("Bad input: " + bad_input);
continue;
}
}
continuein the catch block?