cop2800 quiz5 – Flashcards
Unlock all answers in this set
Unlock answersquestion
1. All exceptions are subclasses of the __class.
a. Exception
b. Throwable
c. Error
d. RuntimeException
answer
Exception
question
2. To determine the cause of an unhandled exception, you can
a. use the name of the exception class that's displayed
b. use the error message that's displayed
c. use the information in the stack trace
d. all of the others
answer
all of the others
question
3. What is the main reason for using a generic data validation method?
a. It runs faster than validation code in the main method
b. It saves you from writing variations of the same code again and again to check multiple data entries
c. It prevents NumberFormatExceptions from being thrown
d. None of the others
answer
It saves you from writing variations of the same code again and again to check multiple data entries
question
4. When a statement within a try block causes an exception, the remaining state-ments in the try block
a. are executed after the statements in the catch block
b. are executed before the statements in the catch block
c. aren't executed
answer
aren't executed
question
5. When is the code within a catch block executed
a. When the code in the try block doesn't compile
b. When the exception specified in the catch block is thrown in the try block
c. When the try block finishes executing
d. When a runtime error occurs
answer
When the exception specified in the catch block is thrown in the try block
question
6. You should validate user entries rather than catch and handle exceptions caused by invalid entries whenever possible because
a. your code will run faster
b. data validation code should only be used for situations that are truly ex-ceptional
c. you can more accurately determine the cause of an invalid entry
d. allof the others
answer
your code will run faster
question
7. Which of the following classes define exceptions that can occur in a Java ap-plication?
a. ArithmeticException
b. NumberFormatException
c. NullPointerException
d. All of the others
answer
All of the others
question
Output Example 5
8. (Refer to Output Example 5) What is this output called?
a. a stack trace
b. a method log
c. an exception handler
d. an exception hierarchy
answer
a stack trace
question
9.(Refer to Output Example 5) What caused the exception to occur?
a. The user didn't enter the type of data the program was expecting
b. The program couldn't format the double value that the user entered
c. You can't tell from the information given
answer
The user didn't enter the type of data the program was expecting
question
10. (Refer to Output Example 5) What is the order of method calls
a. java.util.Scanner.throwFor calls java.util.Scanner.next calls java.util.Scan-ner.nextDouble calls FutureValueApp.main
b. FutureValueApp.main calls java.util.Scanner.nextDouble calls java.util.Scanner.next calls java.util.Scanner.throwFor
c. you can't tell from the information given
answer
FutureValueApp.main calls java.util.Scanner.nextDouble calls java.util.Scanner.next calls java.util.Scanner.throwFor