Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Chapter 24 – C How to Program 6e Multiple Choice Test Bank


 

Download  file with the answers

Not a member!
Create a FREE account here to get access and download this file with answers


Chapter 24: Exception Handling

Section 24.1 Introduction

24.1 Q1: Exception handling may allow a program to:
a. Terminate in a controlled manner.
b. Be more robust and fault-tolerant.
c. Continue executing as if no problem was encountered.
d. All of the above.

Section 24.2 Example: Handling an Attempt to Divide by Zero

24.2 Q1: The correct order in which an exception is detected and handled is:
a. try, catch, throw
b. throw, catch, try
c. catch, throw, try
d. try, throw, catch

24.2 Q2: Once an exception is thrown, when can control return to the throw point?
a. Never.
b. Only after the exception is caught.
c. Once the stack unwinding process is completed.
d. Immediately after the exception is thrown.

24.2 Q3: The try block cannot:
a. Enclose the code that may throw the exception.
b. Enclose its own catch blocks.
c. Test enclosing try blocks for additional catch statements if this try block’s catch statements can’t match the exception being thrown.
d. Have exceptions explicitly or implicitly thrown in the try block itself.

24.2 Q4: catch blocks are not required to contain:
a. Braces { }.
b. Parentheses ( ).
c. Some form of parameter type indication.
d. A parameter name.

24.2 Q5: An exception:
a. Terminates program execution.
b. Terminates the block where the exception occurred.
c. Will terminate the block where the exception occurred unless a catch command stops it.
d. Will not terminate a block unless explicitly instructed to do so.

Section 24.3 When to Use Exception Handling

24.3 Q1: Exception handling should not be used:
a. As an alternative for program control.
b. To make error handling uniform on large projects.
c. To deal with errors that do not arise very often.
d. To deal with errors for components that will be widely used in other applications, such as classes and libraries.

Section 24.4 Rethrowing an Exception

24.4 Q1: To rethrow an exception, the exception handler must:
a. Use the throw; statement.
b. Use the throw command with the same parameters as the original exception.
c. Return a reference to whatever caused the original exception.
d. Not have attempted to process that exception at all.

24.4 Q2: Select the false statement. A rethrown exception:
a. Is detected by the next enclosing try block.
b. Is the immediate result of a throw command.
c. Can be processed by exception handlers following the enclosing try block.
d. Must have been fully processed at the time it was rethrown.

Section 24.5 Exception Specifications

24.5 Q1: The proper syntax for a throw list is:
a. int g( double h )
throw ( a, b, c )
b. int g( double h )
throw ( a b c )
c. int g( double h )
throw ( a )
throw ( b )
throw ( c )
d. int g( double h )
throw ( a ),
throw ( b ),
throw ( c )

24.5 Q2: Placing throw() after a function’s parameter list:
a. Guarantees that all exceptions can be thrown in this function.
b. Guarantees that only programmer-defined exceptions can be thrown in this function.
c. Indicates that throwing an exception in this function would call unexpected.
d. Indicates that the compiler will issue an error if the function contains a throw expression.

Section 24.6 Processing Unexpected Exceptions

24.6 Q1: Select the false statement. The functions set_terminate and set_unexpected:
a. Return pointers to the last function called by terminate and unexpected, respectively.
b. Each return 0 the first time they are called.
c. Take as arguments pointers to void functions with no arguments.
d. Have their prototypes in header file .

24.6 Q2: Which of the following is not a case in which function terminate is called?
a. When the exception mechanism cannot find a matching catch for a thrown exception.
b. When the abort function is called before any call to function set_abort.
c. When a destructor attempts to throw an exception during stack unwinding.
d. When an attempt is made to rethrow an exception when there is no exception currently being handled.

Section 24.7 Stack Unwinding

24.7 Q1: The purpose of stack unwinding is to:
a. Attempt to catch exceptions that are not caught in their scope.
b. Improve catch blocks by allowing them to handle multiple exceptions.
c. Return control to the function that created the exception.
d. Aid the terminate command in shutting down the program.

Section 24.8 Constructors, Destructors and Exception Handling

24.8 Q1: Select the false statement. If an exception is thrown from a constructor:
a. The object being constructed will not be constructed.
b. For an array, destructors for all array elements are called, even if those array elements have not yet been constructed.
c. The exception can contain the error information that the constructor would not be able to return in the normal manner.
d. For an object with member objects, and whose outer object has not been constructed, the destructor is called for the member objects.

Section 24.9 Exceptions and Inheritance

24.9 Q1: An advantage of using inheritance with exceptions is:
a. The ability to catch related errors easily.
b. Allowing catch statements to be imported into classes.
c. The ability to explicitly test for derived class objects individually.
d. The simplification of destructor calls for objects.

Section 24.10 Processing new Failures

24.10 Q1: Select the false statement. Depending on the compiler:
a. A failed new operation can return a 0.
b. A failed new operation can throw a bad_alloc exception.
c. A failed new operation can throw an exception if the header file has been included.
d. A failed new operation can automatically be caught at compile time.

24.10 Q2: Select the false statement. The new operator:
a. Can attempt to allocate as much memory as the programmer requests.
b. Returns a pointer to a location in memory.
c. Can indicate failure differently on different compilers.
d. Throws a bad_alloc exception regardless of what function is registered with set_new_handler.

Section 24.11 Class unique_ptr and Dynamic Memory Allocation

24.11 Q1: If dynamic memory has been allocated for an object and an exception occurs, then:
a. The catch block will not work properly.
b. A memory leak could result.
c. The object’s constructor will cause another exception.
d. Multiple pointers to memory could be created.

24.11 Q2: Which statement about class unique_ptr (of the new C++ standard) and dynamic memory allocation is false?
a. An object of class unique_ptr maintains a pointer to dynamically allocated memory.
b. When a unique_ptr object destructor is called (for example, when a unique_ptr object goes out of scope), it performs a destroy operation on its pointer data member.
c. Class template unique_ptr provides overloaded operators * and -> so that a unique_ptr object can be used just as a regular pointer variable is.
d. Class unique_ptr is part of the new C++ standard and it replaces the deprecated auto_ptr class.

Section 24.12 Standard Library Exception Hierarchy

24.12 Q1: Select the false statement regarding exceptions.
a. The C++ standard has a hierarchy of exception classes.
b. All exception classes are accessible via .
c. Several classes derive from class exception.
d. The what function can be overridden in each class derived from exception.

24.12 Q2: Which class indicates that an error occurred in which an arithmetic result was larger than the largest number that can be stored in the computer?
a. invalid_argument.
b. bad_exception.
c. out_of_range.
d. overflow_error.

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!