Once an exception is caught in this code, the menuSystem
method is run, but once I go to input a number the programme closes and the \"Build is successful\" mes
Put the try
and catch
within the while
loop. If the code is using nextInt()
then you need to skip the invalid input as it will not be consumed in the event of a mismatch.
It would be possible to avoid the exception handling for InputMismatchException
by using the hasNextInt()
methods of Scanner
until a valid input is entered before attempting to consume it:
while (!kb.hasNextInt()) kb.next();