i have this piece of code. I wanted to return to the beginning of loop and ask for user input again. However, it always loops without stopping to ask for input. What is wron
This should throw and catch the exception and the continue
command should send you back to your while loop
. you need either a continue or a flag
to tell your while when it stops being true
.
while(true)
{
try
{
int choice = input.nextInt();
throw new InputMismatchException();
}
catch (InputMismatchException e)
{
continue;
}
}