Solved

Why Does the Following Code Cause a Compiler Error? Try

Question 13

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

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents