Hw11

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

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.

a. It specifies the point at which the exception must be handled.

Unchecked exceptions are also known as ___________ exceptions in java. a. Run-time b. Try c. Compile time d. Catch

a. Run-time

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).

c. Both (a) and (b).

Checked exceptions are also known as _____________ exceptions in java. a. Run-time b. Try c. Compile time d. Catch

c. Compile time

Which of the following are types of assertions? a. Preconditions. b. Postconditions. c. Conditions in control statements. d. (a) and (b).

d. (a) and (b).

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.

a. The throw statement is used to throw an exception.

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

a. after the last catch block (or the finally block, if there is one), termination

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.

a. control proceeds to the first statement after the finally block.

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.

b. Exception handling can catch but not resolve exceptions.

You can write only a "try block" without "catch and finally blocks". a. True b. False

b. False

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.

b. The name of catch block's exception parameter.

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.

b. the compiler will issue an error message indicating that the exception must be caught or declared.

When an exception occurs it is said to have been ________. a. caught. b. thrown. c. declared. d. handled.

b. thrown.

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.

c. Like any other class, an exception class can contain fields and methods.

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.

c. The finally block and try block can appear in any order.

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.

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.

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.

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.

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.

c. an original exception that was caught before the current exception was thrown.

All exception classes inherit, either directly or indirectly, from ________. a. class Error. b. class RuntimeException. c. class Throwable. d. None of the above.

c. class Throwable.

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.

c. is an exception that occurs for which there are no matching catch clauses.

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.

c. specifies the exceptions a method throws.

Which of these keywords is not a part of exception handling? a. try b. finally c. thrown d. catch

c. thrown

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.

c. try block.

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. All of the above.

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.

d. All of the above.

Which of the following errors is synchronous? a. Divide by zero. b. Arithmetic overflow. c. Unsuccessful memory allocation. d. All of the above.

d. All of the above.

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.

d. Instructions on handling the exception.

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.

d. None of the above are true.

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.

d. The string returned from class Throwable's getMessage method contains the name of the exception's class.

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.

d. The try block should contain statements that may throw an exception.


संबंधित स्टडी सेट्स

ATI Priority Setting Frameworks Advanced Test

View Set

Chapter 1: The Twenty First Century Entrepreneur

View Set

Simulation Lab 3.1: Module 03 Change IPv6 Auto-Configuration Settings

View Set