Unit 12 Reviewing the Basics Quiz

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Two of the following statements are true, and one is false. Identify the false statement:

***a. When multiple try block statements throw exceptions, multiple catch blocks might execute.*** b. As soon as an exception occurs, the try block that contains it is abandoned and the rest of its statements are unexecuted. c. When a program contains multiple catch blocks, the first one that matches the thrown Exception type is the one that executes.

Two of the following statements are true, and one is false. Identify the false statement:

**a. You must create your own Exception classes for your programs to be considered truly object oriented. ** b. The Exception class contains four constructors, including a default constructor and one that requires a String that contains the message that can be returned by the getMessage() method. c. To create your own throwable Exception class, you should extend the Exception class.

The memory location where the computer stores the list of method locations to which the system must return is known as the registry.

False

When a try block does not generate an Exception and you have included multiple catch blocks, only the first matching one executes.

False

All Java Exceptions are ____________.

Throwables

Any method can throw an Exception.

True

The segment of code that handles or takes appropriate action following an exception is a catch block.

True

Two of the following statements are true, and one is false. Identify the false statement:

a. An advantage to using object-oriented error-handling techniques is that programs are clearer and more flexible. b. In many cases, you want a method to check for errors, but you do not want to require the method to handle an error if it finds one. **c. An advantage to using object-oriented error-handling techniques is that when a method throws an exception, it will always be handled in the same, consistent way**

Two of the following statements are true, and one is false. Identify the false statement:

a. Exception specification is the practice of listing possible exceptions in a throws clause in a method header. **b. If you write a method with a throws clause for a checked exception in the header, then any method that uses your method must catch and handle the possible exception.** c. Many exceptions never have to be explicitly thrown or caught, nor do you have to include a throws clause in the headers of methods that automatically throw these exceptions

The method that ends the current application and returns control to the operating system is ____________.

a. System.exit()

Two of the following statements are true, and one is false. Identify the false statement:

a. The Boolean expression in an assert statement should always be true if the program is working correctly. **b. All logic errors cause a program to terminate, and they should be handled by throwing and catching exceptions.** c. To enable an assertion, you must use the -ea option when you execute the program.

Two of the following statements are true, and one is false. Identify the false statement:

a. The Error class represents serious errors from which your program usually cannot recover, but the Exception class comprises less serious errors from which the program can recover. ***b. When exceptions occur, object-oriented programs must handle them.** c. Exception handling is the name for the object-oriented techniques used to manage runtime errors.

Two of the following statements are true, and one is false. Identify the false statement:

a. The call stack is where the computer stores the list of locations to which the system must return after each method call. b. When you catch an exception, you can call printStackTrace() to display a list of methods in the call stack so you can determine the location of the statement that caused the exception. However, usually you do not want to place a printStackTrace() method call in a finished program. **c. When a method throws an exception and the method does not catch it, the exception is thrown to the next method down the call stack, or in other words, to the next method that the offending method calls.**

Two of the following statements are true, and one is false. Identify the false statement:

a. Usually, you use a finally block to perform cleanup tasks that must happen regardless of whether any exceptions occurred and whether any exceptions that occurred were caught. **b. The code within a finally block executes when a try block identifies an exception that is not caught. ** c. It's possible that the code that follows a try...catch...finally sequence might never execute—for example, if a try block throws an unhandled exception

Two of the following statements are true, and one is false. Identify the false statement:

a. You can write functional Java programs without using exception-handling techniques. **b. You must have a touch screen to be able to display a virtual keyboard on a Windows system.** c. The Runtime class exec() method throws an IOException.

Two of the following statements are true, and one is false. Identify the false statement:

a. You usually code at least one catch block immediately following a try block to handle an exception that might be thrown by the try block. b. A try block is a block of code you attempt to execute while acknowledging that an exception might occur. ***c. A throw statement is one that sends an Exception object to a try block so it can be handled.***

You ____________ within a try block.

a. can place any number of statements

A method can ____________.

a. either handle errors but not check for them or check for errors but not handle them

A try block includes all of the following elements except ____________.

a. the keyword catch

A(n) ____________ is a statement used in testing programs that should be true; if it is not true, an Exception is thrown.

assertion

Which of the following statements is true?

b. Errors are more serious than Exceptions.

The catch block that begins catch(Exception e) can catch Exceptions of type ____________.

c. both IOException and ArithmeticException

The code within a finally block executes when the try block ____________.

c. identifies an Exception or not, whether or not any Exceptions are caught

An advantage to using a try...catch block is that exceptional events are ____________.

c. isolated from regular events

If you include three statements in a try block and follow the block with three catch blocks, and the second statement in the try block throws an Exception, then ____________.

c. the first matching catch block executes

You can get a list of the methods through which an Exception has traveled by using the ____________ method.

d. printStackTrace()

Which of the following is least important to know if you want to be able to use a method to its full potential?

d. the number of statements within the method

In object-oriented programming terminology, an unexpected or error condition is a(n) ____________.

exception

A method that detects an error condition or Exception ____________ an Exception.

throws

In object-oriented terminology, you ____________ a procedure that might not complete correctly.

try


Kaugnay na mga set ng pag-aaral

AP Psychology (Motivation and Emotion)

View Set

Chapters 1-3: Basic Economic Concepts

View Set

Extra HESI 290 Practice Questions

View Set

BUS112 Chapter 13: Subculture and Social Class

View Set

Homework 7.4 Costs in the Long Run

View Set

Certificate in ESG Investing Edition 1

View Set