Deck 16: Exception Handling
Question
Question
Question
Question
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/24
Play
Full screen (f)
Deck 16: Exception Handling
1
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 )
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 )
A
2
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.
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.
C
3
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.
B
4
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.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
5
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.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
6
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 24 flashcards in this deck.
Unlock Deck
k this deck
7
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 24 flashcards in this deck.
Unlock Deck
k this deck
8
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 24 flashcards in this deck.
Unlock Deck
k this deck
9
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 24 flashcards in this deck.
Unlock Deck
k this deck
10
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 24 flashcards in this deck.
Unlock Deck
k this deck
11
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 24 flashcards in this deck.
Unlock Deck
k this deck
12
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.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
13
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 24 flashcards in this deck.
Unlock Deck
k this deck
14
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 24 flashcards in this deck.
Unlock Deck
k this deck
15
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.
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.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
16
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 24 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following is an advantage of not using exception-handling to deal with errors?
A) Intermixing program logic with error-handling logic can make the program more difficult to read, modify, maintain and debug.
B) Frequent tests for infrequently occurring errors can degrade a program's performance.
C) Programmers may delay writing error-processing code or sometimes forget to include it.
D) None of the above.
A) Intermixing program logic with error-handling logic can make the program more difficult to read, modify, maintain and debug.
B) Frequent tests for infrequently occurring errors can degrade a program's performance.
C) Programmers may delay writing error-processing code or sometimes forget to include it.
D) None of the above.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
18
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 24 flashcards in this deck.
Unlock Deck
k this deck
19
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 24 flashcards in this deck.
Unlock Deck
k this deck
20
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.
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
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
21
Both "ignoring the exception" and "aborting the program" are error-handling techniques that:
A) Cannot be used if the error is fatal.
B) Always result in a resource leak.
C) Should not be used for mission-critical applications.
D) Allow program execution to proceed as if no error had occurred.
A) Cannot be used if the error is fatal.
B) Always result in a resource leak.
C) Should not be used for mission-critical applications.
D) Allow program execution to proceed as if no error had occurred.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
22
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 24 flashcards in this deck.
Unlock Deck
k this deck
23
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 24 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following is not an error-handling technique?
A) exit.
B) longjump.
C) ifndef.
D) set_new_handler.
A) exit.
B) longjump.
C) ifndef.
D) set_new_handler.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck