Chapter Questions
If your program contains an API method call, you should put it inside a try block. To be fully compliant with proper coding practice, you should apply this rule for all your API method calls. $(\mathrm{T} / \mathrm{F})$.
A try block and its associated catch block(s) must be contiguous. (T / F).
Usually, you should try to aggregate related dangerous statements in the same try block to minimize clutter. $(\mathrm{T} / \mathrm{F})$
Where should you put safe statements that use the results of dangerous operations?
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 / $\mathrm{F}$ )
In checking for compile-time errors, the compiler takes into account that all statements inside a try block might get skipped. (T / F)
If an exception is derived from the RuntimeException class it is a(n) ___________ exception.
Checked exceptions are exceptions that are in or derived from the __________ class, but not in orderived from the___________ class.
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.c) Put it in a try block, and catch it in a following catch block.
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).
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 / $\mathrm{F}$ )
Is it OK to include code that can throw both unchecked and checked exceptions in the same try block?
What type of exception matches all checked exceptions and all unchecked exceptions except those derived from the Error class?
What does the getMessage method return?
For each distinct type of exception that might be thrown, there must be a separate catch block. (T / F)
The compiler automatically checks for out-of-order catch blocks. (T / $\mathrm{F}$ )
What are the two types of information displayed by the JVM when it encounters a runtime error that terminates execution?
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?
Given a non-void method that contains no try and catch blocks. If the method throws an exception, we know that the JVM transfers the thrown exception back to the calling method. But does the JVM return a value (with a return statement) to the calling module?