Multiple choice technology architecture

try {int x = Integer.parseInt(“one”);} Which of the following could be used to create appropriate catch block ?

  1. ClassCastException

  2. IllegalStateException

  3. NumberFormatException

  4. None

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Integer.parseInt throws NumberFormatException when the string cannot be parsed as a valid integer. The string 'one' contains letters, not digits, so parsing fails. ClassCastException is for incompatible type conversions, and IllegalStateException is for invalid state timing.