Lets look at the specification of these two exception classes :
InputMismatchException
is specific for the Scanner
. It indicates invalid type, not necessarily an invalid number. NumberFormatException
is specific for trying to convert a non numeric string to a number.
public class InputMismatchException extends NoSuchElementException
Thrown by a Scanner to indicate that the token retrieved does not match the pattern for the expected type, or that the token is out of range for the expected type.
public class NumberFormatException extends IllegalArgumentException
Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format.