Page 627 - Introduction to Programming with Java: A Problem Solving Approach
P. 627
2. A try block and its associated catch block(s) must be contiguous. (T / F) §14.5 try Block Details
3. Usually, you should try to aggregate related dangerous statements in the same try block to minimize clutter. (T / F)
4. Where should you put safe statements that use the results of dangerous operations?
5. If an exception is thrown, the JVM jumps to a matching catch block, and after executing the catch
block, it returns to the try block at the point where the exception was thrown. (T / F)
6. In checking for compile-time errors, the compiler takes into account that all statements inside a try block
might get skipped. (T / F)
§14.6 Two Categories of Exceptions—Checked and Unchecked
7. If an exception is derived from the RuntimeException class it is a(n) exception.
8. Checked exceptions are exceptions that are in or derived from the class, but not in or
derived from the class.
§14.7 Unchecked Exceptions
9. In the following list, indicate whether each option is a viable option for an unchecked exception that you know your program might throw:
a) Ignore it.
b) Rewrite the code so that the exception never occurs.
Review Questions 593
c) Put it in a try block, and catch it in a following catch block. §14.8 Checked Exceptions
Apago PDF Enhancer
10. When a statement might throw a checked exception, you can keep the compiler from complaining if you put that statement in a try block and follow the try block with a catch block whose parameter type is the same as the exception type. (T / F)
11. You can determine whether a particular statement contains a checked exception and the type of that exception by attempting to compile with no try-catch mechanism. (T / F)
§14.9 The Exception Class and Its getMessage Method
12. Is it OK to include code that can throw both unchecked and checked exceptions in the same try block?
13. What type of exception matches all checked exceptions and all unchecked exceptions except those derived
from the Error class?
14. What does the getMessage method return?
§14.10 Multiple Catch Blocks
15. For each distinct type of exception that might be thrown, there must be a separate catch block. (T / F)
16. The compiler automatically checks for out-of-order catch blocks. (T / F) §14.11 Understanding Exception Messages
17. What are the two types of information displayed by the JVM when it encounters a runtime error that terminates execution?
§14.12 Using throws <exception-type> to Postpone the catch
18. Suppose you want to postpone catching of a NumberFormatException. What should you append to the
heading of a method to alert the compiler and a potential user that something in the method might throw that type of exception?