Obviously what I wrote is a gross over‑simplification. NumberFormatException (NFE) doesn't follow those rules; you can sometimes recover by a new entry. When reading from a file, however, an NFE may mean the the format of the file and the format expected by the program are different. You have to be very careful with formats of text files, therefore.
InputMismatchException (IME) is similar, but is thrown by
Scanners. If you are using a Scanner to read from the keyboard, there are two ways you can suffer an IME. One is using nextLine after nextSomethingElse, as in
this thread. The other is incorrectly formated input, which Rob Spoor points out as totally avoidable:-
Rob Spoor wrote:. . . check for input.hasNext:
I think I forgot the hasNext() before in the loop, but that could cause an exception with the input.next() call if the stream is closed.