Programming Languages Chapter 11 The try block must be followed by at least

subject Type Homework Help
subject Pages 7
subject Words 1787
subject Authors Harvey Deitel, Paul Deitel

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Chapter 11: Exception Handling
Section 11.1 Introduction
11.1 Q1: 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.
11.2 Q1: When an exception occurs it is said to have been ________.
a. caught.
b. thrown.
c. declared.
d. handled.
11.2 Q2: 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.
11.2 Q3: 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.
page-pf2
11.3 Q1: 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.
11.3 Q2: 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.
11.3 Q3: 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.
11.3 Q4: 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.
11.3 Q5: 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.
page-pf3
11.3 Q6: 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
11.3 Q7: 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.
11.3 Q8: 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.
11.4 Q1: Which of the following errors is synchronous?
a. Divide by zero.
b. Arithmetic overflow.
c. Unsuccessful memory allocation.
d. All of the above.
page-pf4
11.5 Q1: All exception classes inherit, either directly or indirectly, from ________.
a. class Error.
b. class RuntimeException.
c. class Throwable.
d. None of the above.
11.5 Q2: Which of the following exceptions is a checked exception?
a. ArithmeticException.
b. IOException.
c. RuntimeException.
d. InputMismatchException.
11.5 Q3: 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.
11.6 Q1: 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.
11.6 Q2: 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.
page-pf5
c. The code in a finally block is executed only if there are no catch blocks.
d. None of the above are true.
11.6 Q3: 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.
11.6 Q4: 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.
11.7 Q1: 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.
11.7 Q2: 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.
page-pf6
11.8 Q1: 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.
11.9 Q1: Which of the following statements is true?
a. Using existing exceptions makes the program less robust.
b. Always create your own exception classes.
c. Like any other class, an exception class can contain fields and methods.
d. The new exception class should extend RuntimeException if the program should
be required to handle the exception.
11.10 Q1: 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).
11.11 Q1: Which of the following are types of assertions?
a. Preconditions.
b. Postconditions.
c. Conditions in control statements.
d. (a) and (b).
page-pf7
11.12 Q1: 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
interfacesuch a class has a close method.

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.