Java Reference
In-Depth Information
TABLE 11-3 Some of Java's Exception Classes (continued)
Exception Class
Description
NumberFormatException
Use of an illegal number format
A string index is either less than 0 or
greater than or equal to the length of
the string.
StringIndexOutOfBoundsException
Input (token) retrieved does not
match the pattern for the expected
type, or the token is out of range for
the expected type.
InputMismatchException
The Java application programs in the preceding chapters used the class Scanner and its
methods nextInt , nextDouble , next , and nextLine to input data into the programs.
As shown by Sample Run 3 of Example 11-1, if the user enters an invalid value, the
program terminates with an error message indicating an InputMismatchException .
This exception is thrown by the method nextInt . In addition to the
InputMismatchException , the methods nextInt and nextDouble can throw other
exceptions, as shown in Tables 11-4 and 11-5.
TABLE 11-4 Exceptions Thrown by the Method nextInt
Exception Thrown
Description
If the next input (token) is not an integer or
is out of range
InputMismatchException
NoSuchElementException
If the input is exhausted
IllegalStateException
If this scanner is closed
TABLE 11-5 Exceptions Thrown by the Method nextDouble
Exception Thrown
Description
If the next input (token) is not a floating-
point number or is out of range
InputMismatchException
NoSuchElementException
If the input is exhausted
IllegalStateException
If this scanner is closed
Search WWH ::




Custom Search