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
Q14: The ability to catch multiple types of
Q17: When an exception is thrown:
A) it must
Q18: The following catch statement can: catch (Exception
Q20: The exception classes are in packages in
Q21: In order for an object to be
Q22: If, within one try statement you want
Q23: To serialize an object and write it
Q24: When you write a method that throws
Q28: In a try/catch construct, after the catch
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