Stack Trace for an InputMismatchException
In the third execution, the user enters the string "hello"
as the denominator. Notice again that a stack trace is displayed. This informs us that an InputMismatchException
has occurred (package java.util
). Our prior examples that input numeric values assumed that the user would input a proper integer value. However, users sometimes make mistakes and input noninteger values. An InputMismatchException occurs when Scanner
method nextInt
receives a string
that does not represent a valid integer. Starting from the end of the stack trace, we see that the exception was detected in line 20 of method main
. Moving up the stack trace, we see that the exception occurred in method nextInt
. Notice that in place of ...
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.