I wrote this simple code to fetch a double and just keep asking until one was given, but when you give a string it just turns into an infinite loop and I can't figure out why. Any reason why it behaves this way?
Scanner scanner = new Scanner(System.in);
double x = 0.0d;
while (true) {
try {
System.out.println("Gimme a double:");
x = scanner.nextDouble();
break;
} catch (InputMismatchException e) {}
}
System.out.println(x);