Try-Catch inside While Loop
问题 The code below asks the user how many racers he/she would like. while (true) { // loops forever until break try { // checks code for exceptions System.out.println("How many racers should" + " participate in the race?"); amountRacers = in.nextInt(); break; // if no exceptions breaks out of loop } catch (InputMismatchException e) { // if an exception appears prints message below System.err.println("Please enter a number! " + e.getMessage()); continue; // continues to loop if exception is found