No, you don't want to get your input in the catch block, but rather want to warn the user of bad input in that block. Instead, set a boolean in the try block after the scanner's nextInt()
. Surround the whole thing in a while loop, and only exit the while loop when the boolean has been successfully set.
Pseudocode:
initialize boolean variable, inputStillBad to true.
while inputStillBad
try block
prompt user for input
get input from scanner
if this line was reached, then scanner succeeded
check if year is within bounds, and if so:
set inputStillBad to false.
else:
warn user that the year was out of range
catch your exception here
warn the user that they entered non-numeric input
end while loop