Hi all, I've got a problem relating to error reporting. In the code posted below, when the user actually presses enter after reading the error, the program does not loop back to the main menu, but merely repeats the error. If I remove the "input.nextLine();" code in line 17, then the program does loop back to the main menu. Anyone got any idea as to what the problem could be?
do {
try {
System.out.println("\nWelcome to Telephone Directory!");
System.out.println("===============================");
System.out.println("\n1.)Add Record");
System.out.println("2.)Search Records");
System.out.println("3.)Edit Record");
System.out.println("4.)Delete Record");
System.out.println("5.)Display All Records");
System.out.println("6.)Quit");
menuChoice = input.nextInt();
} catch (Exception e) {
Scanner input = new Scanner(System.in);
System.out.println("\nERROR: CHOICE MUST BE OF INTEGER NATURE. \nPress ENTER to return to main menu");
input.nextLine();
}
} while (menuChoice != 6);
Thanks :)