Solved

Why Does the Following Code Cause a Compiler Error

Question 4

Multiple Choice

Why does the following code cause a compiler error?
Try
{
Number = Integer.parseInt(str) ;
}
Catch (IllegalArgumentException e)
{
System.out.println("Bad number format.") ;
}
Catch (NumberFormatException e)
{
System.out.println(str + " is not a number.") ;
}


A) Because you can have only one catch clause in a try statement
B) Because NumberFormatException inherits from IllegalArgumentException. The code should handle NumberFormatException before IllegalArgumentException
C) Because the Integer.parseInt method does not throw a NumberFormatException
D) Because the Integer.parseInt method does not throw an IllegalArgumentException

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions