I am trying to do a chess game and at a certain point the user inputs a number relating to what piece they want to move. I had a simplified version of the code below earlier, but I recently decided to put a 'try' and 'catch' statement to catch the InputMismatchException. This is the code:
int inputexception = 0;
do {
inputexception = 0;
try {
System.out.println("What piece would you like to move?");
pieceselectioninput = scan.nextInt();
} catch ( InputMismatchException e ){
inputexception = 1;
}
} while ( inputexception == 1 );
So once I run this program, if I input a non-Int value, it repeats on and on forever with "What piece would you like to move?" being displayed on the screen continuously until I manually terminate the program.
What am I doing wrong? It wasn't like this until I added the 'try' and 'catch' phrases.