Deck 17: Exception Handling: a Deeper Look
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/20
Play
Full screen (f)
Deck 17: Exception Handling: a Deeper Look
1
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.
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.
B
2
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.
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.
B
3
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.
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.
A
4
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.
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.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
5
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.
A) invalid_argument.
B) bad_exception.
C) out_of_range.
D) overflow_error.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
6
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.
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.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
7
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.
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.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
8
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.
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.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
9
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.
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.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
10
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.
A) Never.
B) Only after the exception is caught.
C) Once the stack unwinding process is completed.
D) Immediately after the exception is thrown.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
11
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.
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.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
12
Catch blocks are not required to contain:
A) Braces { }.
B) Parentheses ( ).
C) Some form of parameter type indication.
D) A parameter name.
A) Braces { }.
B) Parentheses ( ).
C) Some form of parameter type indication.
D) A parameter name.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
13
To initialize a unique_ptr, you can use C++14's ________ function template, which allocates dynamic memory with operator new, then returns a unique_ptr to that memory. Prior to C++14, you'd pass the result of a new expression directly to unique_ptr's constructor.
A) create_unique
B) make_unique
C) get_unique
D) form_unique
A) create_unique
B) make_unique
C) get_unique
D) form_unique
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
14
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.
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.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
15
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.
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.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
16
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.
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.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following statements is false?
A) As of C++11, if a function does not throw any exceptions and does not call any functions that throw exceptions, you can explicitly state that a function does not throw exceptions by placing noexcept to the right of the function's parameter list in both the prototype and the definition.
B) Labeling a function noexcept indicates to client-code programmers that there's no need to call the function in a try block.
C) For a const member function, you must place noexcept after const.
D) If a function that's declared noexcept calls another function that throws an exception or executes a throw statement, the program returns to its caller.
A) As of C++11, if a function does not throw any exceptions and does not call any functions that throw exceptions, you can explicitly state that a function does not throw exceptions by placing noexcept to the right of the function's parameter list in both the prototype and the definition.
B) Labeling a function noexcept indicates to client-code programmers that there's no need to call the function in a try block.
C) For a const member function, you must place noexcept after const.
D) If a function that's declared noexcept calls another function that throws an exception or executes a throw statement, the program returns to its caller.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
18
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.
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
D) A failed new operation can automatically be caught at compile time.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
19
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.
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.
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck
20
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
A) try, catch, throw
B) throw, catch, try
C) catch, throw, try
D) try, throw, catch
Unlock Deck
Unlock for access to all 20 flashcards in this deck.
Unlock Deck
k this deck