Tag Archives: Java Virtual Machine

java.util.InputMismatchException – How to solve InputMismatchException


java.util.InputMismatchException – How to solve InputMismatchException

In this tutorial we will discuss about the InputMismatchException in Java. This exception is thrown by an instance of the Scanner class to indicate that a retrieved token does not match the pattern for the expected type, or that the retrieved token is out of range.

The InputMismatchException class extends the NoSuchElementException class, which is used to indicate that the element being requested does not exist. Furthermore, the NoSuchElementException class extends the RuntimeExceptionclass and thus, belongs to those exceptions that can be thrown during the operation of the Java Virtual Machine (JVM). It is an unchecked exception and thus, it does not need to be declared in a method’s or a constructor’s throws clause.

Finally the InputMismatchException class exists since the 1.5 version of Java.