Deck 11: Exception Handling: a Deeper Look

Full screen (f)
exit full mode
Question
Exceptions can be thrown by ________.

A) the Java Virtual Machine.
B) code in a try block.
C) calls from a try block to other methods.
D) All of the above.
Use Space or
up arrow
down arrow
to flip the card.
Question
If the catch-or-declare requirement for a checked exception is not satisfied ________.

A) the compiler will issue an error message indicating that the exception must be caught.
B) the compiler will issue an error message indicating that the exception must be caught or declared.
C) a stack trace will be displayed indicating the exception that has occurred and where it occurred.
D) a stack trace will be displayed, along with a message indicating that the exception must be caught.
Question
In Java, after an exception is handled, control resumes . This is known as the model of exception handling.

A) after the last catch block (or the finally block, if there is one), termination
B) after the last catch block (or the finally block, if there is one), resumption
C) just after the throw point, termination
D) just after the throw point, resumption
Question
Which of the following exceptions is a checked exception?

A) ArithmeticException.
B) IOException.
C) RuntimeException.
D) InputMismatchException.
Question
To catch an exception, the code that might throw the exception must be enclosed in a ________.

A) throws block.
B) catch block.
C) try block.
D) finally block.
Question
What is the difference between a try block and a try statement?

A) There is no difference; the terms can be used interchangeably.
B) A try statement refers to the block of code following the keyword try, while the try block refers to the try keyword and the block of code following this keyword.
C) The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch and/or finally clauses together form a try statement.
D) The try statement refers to the keyword try followed by a block of code. The try statement and its corresponding catch and/or finally clauses together form a try block.
Question
Which of the following statements is true?

A) The code in a finally block is executed only if an exception occurs.
B) The code in a finally block is executed only if an exception does not occur.
C) The code in a finally block is executed only if there are no catch blocks.
D) None of the above are true.
Question
Which of the following is not included in an exception's stack trace?

A) A descriptive message for the exception.
B) The method-call stack at the time the exception occurred.
C) The name of the exception.
D) Instructions on handling the exception.
Question
Which of the following statements is true?

A) The throw statement is used to throw an exception.
B) The throw statement is used to specify that a method will throw an exception.
C) The throw statement is used to access an exception parameter.
D) All of the above.
Question
All exception classes inherit, either directly or indirectly, from ________.

A) class Error.
B) class RuntimeException.
C) class Throwable.
D) None of the above.
Question
After a finally block has finished executing (and there are no exceptions to be handled), ________.

A) control proceeds to the first statement after the finally block.
B) control returns to the throw point.
C) the application exits.
D) control proceeds to the first statement after the last catch block.
Question
The throws clause of a method:

A) specifies the exceptions a method catches.
B) specifies the exceptions thrown by the calling method.
C) specifies the exceptions a method throws.
D) specifies the exceptions a method throws and catches.
Question
Which of the following statements is false?

A) A finally block is placed after the last catch block.
B) A finally block typically releases resources acquired in the corresponding try block.
C) The finally block and try block can appear in any order.
D) A finally block is optional.
Question
An uncaught exception ________.

A) is a possible exception that never actually occurs during the execution of the program.
B) is an exception that occurs for which the matching catch clause is empty.
C) is an exception that occurs for which there are no matching catch clauses.
D) is another term for a thrown exception.
Question
In the catch block below, what is e?
catch (ArithmeticException e) {
System.err.printf(e);
}

A) The type of the exception being caught.
B) The name of catch block's exception parameter.
C) A finally block.
D) An exception handler.
Question
When an exception occurs it is said to have been ________.

A) caught.
B) thrown.
C) declared.
D) handled.
Question
Which of the following statements about try blocks is true?

A) The try block must be followed by at least one catch block.
B) The try block must be followed by a finally block.
C) The try block should contain statements that may process an exception.
D) The try block should contain statements that may throw an exception.
Question
Which of the following statements is false?

A) Exception handling enables programmers to write robust and fault-tolerant programs.
B) Exception handling can catch but not resolve exceptions.
C) Exception handling can resolve exceptions.
D) All of the above are true.
Question
Which of the following statements regarding the throw point of an exception is false?

A) It specifies the point at which the exception must be handled.
B) It is the initial point at which the exception occurs.
C) It is specified as the top row of the method-call stack at the time the exception occurred.
D) All of the above statements are true.
Question
Which of the following errors is synchronous?

A) Divide by zero.
B) Arithmetic overflow.
C) Unsuccessful memory allocation.
D) All of the above.
Question
Which of the following statements is true?

A) Using existing exceptions makes the program less robust.
B) Always create your own exception classes.
C) An exception class is like any other class; however, a typical new exception class contains no members other than four constructors.
D) The new exception class should extend RuntimeException if the program should be required to handle the exception.
Question
Which of the following statements is false?

A) All exceptions must derive from the class Throwable.
B) The class Throwable provides the method getStackTrace that outputs the stack trace to the standard error stream.
C) The class Throwable provides the method getMessage that returns the descriptive string stored in an exception.
D) The string returned from class Throwable's getMessage method contains the name of the exception's class.
Question
Chained exceptions are useful for finding out about ________.

A) exceptions thrown using the chained keyword.
B) checked exceptions only.
C) an original exception that was caught before the current exception was thrown.
D) the current exception's chain of superclasses.
Question
When an unchecked exception occurs in a method but is not caught, ________.

A) the method-call stack is "unwound."
B) the method terminates.
C) all local variables in that method go out of scope.
D) All of the above.
Question
Which of the following statements about the try-with-resources statement is false?

A) The try-with-resources statement simplifies writing code in which you obtain a resource, use it in a try block and release the resource in a corresponding finally block.
B) You allocate the resource in the parentheses following the try keyword and use the resource in the try block; then the statement implicitly calls the resource's close method at the end of the try block.
C) You allocate the resource in the parentheses following the try keyword and use the resource in the try block; then you explicitly call the resource's close method at the end of the try block.
D) Each resource must be an object of a class that implements the AutoCloseable interface-such a class has a close method.
Question
Which of the following is true?

A) A precondition must be true when a method is invoked.
B) A postcondition must be true when a method successfully returns to its caller.
C) Both (a) and (b).
D) Neither (a) nor (b).
Question
Which of the following are types of assertions?

A) Preconditions.
B) Postconditions.
C) Conditions in control statements.
D) (a) and (b).
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/27
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 11: Exception Handling: a Deeper Look
1
Exceptions can be thrown by ________.

A) the Java Virtual Machine.
B) code in a try block.
C) calls from a try block to other methods.
D) All of the above.
D
2
If the catch-or-declare requirement for a checked exception is not satisfied ________.

A) the compiler will issue an error message indicating that the exception must be caught.
B) the compiler will issue an error message indicating that the exception must be caught or declared.
C) a stack trace will be displayed indicating the exception that has occurred and where it occurred.
D) a stack trace will be displayed, along with a message indicating that the exception must be caught.
the compiler will issue an error message indicating that the exception must be caught or declared.
3
In Java, after an exception is handled, control resumes . This is known as the model of exception handling.

A) after the last catch block (or the finally block, if there is one), termination
B) after the last catch block (or the finally block, if there is one), resumption
C) just after the throw point, termination
D) just after the throw point, resumption
after the last catch block (or the finally block, if there is one), termination
4
Which of the following exceptions is a checked exception?

A) ArithmeticException.
B) IOException.
C) RuntimeException.
D) InputMismatchException.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
5
To catch an exception, the code that might throw the exception must be enclosed in a ________.

A) throws block.
B) catch block.
C) try block.
D) finally block.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
6
What is the difference between a try block and a try statement?

A) There is no difference; the terms can be used interchangeably.
B) A try statement refers to the block of code following the keyword try, while the try block refers to the try keyword and the block of code following this keyword.
C) The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch and/or finally clauses together form a try statement.
D) The try statement refers to the keyword try followed by a block of code. The try statement and its corresponding catch and/or finally clauses together form a try block.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following statements is true?

A) The code in a finally block is executed only if an exception occurs.
B) The code in a finally block is executed only if an exception does not occur.
C) The code in a finally block is executed only if there are no catch blocks.
D) None of the above are true.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following is not included in an exception's stack trace?

A) A descriptive message for the exception.
B) The method-call stack at the time the exception occurred.
C) The name of the exception.
D) Instructions on handling the exception.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
9
Which of the following statements is true?

A) The throw statement is used to throw an exception.
B) The throw statement is used to specify that a method will throw an exception.
C) The throw statement is used to access an exception parameter.
D) All of the above.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
10
All exception classes inherit, either directly or indirectly, from ________.

A) class Error.
B) class RuntimeException.
C) class Throwable.
D) None of the above.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
11
After a finally block has finished executing (and there are no exceptions to be handled), ________.

A) control proceeds to the first statement after the finally block.
B) control returns to the throw point.
C) the application exits.
D) control proceeds to the first statement after the last catch block.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
12
The throws clause of a method:

A) specifies the exceptions a method catches.
B) specifies the exceptions thrown by the calling method.
C) specifies the exceptions a method throws.
D) specifies the exceptions a method throws and catches.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following statements is false?

A) A finally block is placed after the last catch block.
B) A finally block typically releases resources acquired in the corresponding try block.
C) The finally block and try block can appear in any order.
D) A finally block is optional.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
14
An uncaught exception ________.

A) is a possible exception that never actually occurs during the execution of the program.
B) is an exception that occurs for which the matching catch clause is empty.
C) is an exception that occurs for which there are no matching catch clauses.
D) is another term for a thrown exception.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
15
In the catch block below, what is e?
catch (ArithmeticException e) {
System.err.printf(e);
}

A) The type of the exception being caught.
B) The name of catch block's exception parameter.
C) A finally block.
D) An exception handler.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
16
When an exception occurs it is said to have been ________.

A) caught.
B) thrown.
C) declared.
D) handled.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following statements about try blocks is true?

A) The try block must be followed by at least one catch block.
B) The try block must be followed by a finally block.
C) The try block should contain statements that may process an exception.
D) The try block should contain statements that may throw an exception.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following statements is false?

A) Exception handling enables programmers to write robust and fault-tolerant programs.
B) Exception handling can catch but not resolve exceptions.
C) Exception handling can resolve exceptions.
D) All of the above are true.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following statements regarding the throw point of an exception is false?

A) It specifies the point at which the exception must be handled.
B) It is the initial point at which the exception occurs.
C) It is specified as the top row of the method-call stack at the time the exception occurred.
D) All of the above statements are true.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following errors is synchronous?

A) Divide by zero.
B) Arithmetic overflow.
C) Unsuccessful memory allocation.
D) All of the above.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following statements is true?

A) Using existing exceptions makes the program less robust.
B) Always create your own exception classes.
C) An exception class is like any other class; however, a typical new exception class contains no members other than four constructors.
D) The new exception class should extend RuntimeException if the program should be required to handle the exception.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following statements is false?

A) All exceptions must derive from the class Throwable.
B) The class Throwable provides the method getStackTrace that outputs the stack trace to the standard error stream.
C) The class Throwable provides the method getMessage that returns the descriptive string stored in an exception.
D) The string returned from class Throwable's getMessage method contains the name of the exception's class.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
23
Chained exceptions are useful for finding out about ________.

A) exceptions thrown using the chained keyword.
B) checked exceptions only.
C) an original exception that was caught before the current exception was thrown.
D) the current exception's chain of superclasses.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
24
When an unchecked exception occurs in a method but is not caught, ________.

A) the method-call stack is "unwound."
B) the method terminates.
C) all local variables in that method go out of scope.
D) All of the above.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
25
Which of the following statements about the try-with-resources statement is false?

A) The try-with-resources statement simplifies writing code in which you obtain a resource, use it in a try block and release the resource in a corresponding finally block.
B) You allocate the resource in the parentheses following the try keyword and use the resource in the try block; then the statement implicitly calls the resource's close method at the end of the try block.
C) You allocate the resource in the parentheses following the try keyword and use the resource in the try block; then you explicitly call the resource's close method at the end of the try block.
D) Each resource must be an object of a class that implements the AutoCloseable interface-such a class has a close method.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following is true?

A) A precondition must be true when a method is invoked.
B) A postcondition must be true when a method successfully returns to its caller.
C) Both (a) and (b).
D) Neither (a) nor (b).
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following are types of assertions?

A) Preconditions.
B) Postconditions.
C) Conditions in control statements.
D) (a) and (b).
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 27 flashcards in this deck.