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:
Verified
Q1: An exception's default error message can be
Q3: To write data to a binary file
Q8: If the code in a method can
Q11: To read data from a binary file
Q14: The following catch statement can catch (Exception
Q16: Given the following constructor code,which of the
Q17: When an exception is thrown:
A) it must
Q18: The IllegalArgumentException class extends the RuntimeException class,and
Q31: When writing a string to a binary
Q56: In the following code, assume that inputFile
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents