Deck 14: Exception Handling

Full screen (f)
exit full mode
Question
To use the assert function in your program, you should include the statement ____.

A) #include
B) #include
C) #include
D) #include
Use Space or
up arrow
down arrow
to flip the card.
Question
The order of the catch blocks does not affect the program.
Question
An object that is being thrown cannot be an anonymous object.
Question
Which of the following is a valid C++ statement?

A) assert(0 = divisor);
B) assert(divisor != 0);
C) assert(divisor 0);
D) assert(divisor is 0);
Question
In C++, any class can be considered an exception class.
Question
A catch block can have, at most, ____ catch block parameter(s).

A) zero
B) one
C) two
D) three
Question
The function ____ can check whether an expression meets the required conditions; if the conditions are not met, it terminates the program.

A) check
B) look
C) assert
D) what
Question
The statements that may generate an exception are placed in a ____ block.

A) throw
B) finally
C) try
D) catch
Question
Which of the following blocks is designed to catch any type of exception?

A) catch(){ }
B) catch(...){ }
C) catch(*){ }
D) catch(exception){ }
Question
If the catch block with an ellipses (in the heading) is needed, then it should be the first catch block in a sequence of try/catch blocks.
Question
If no exception is thrown in a try block, all catch blocks associated with that try block are ignored.
Question
A(n) ____ is an occurrence of an undesirable situation that can be detected during program execution.

A) crash
B) exception
C) misfire
D) bug
Question
A catch block specifies the type of exception it can catch and immediately terminates the program.
Question
When division by zero occurs and the problem is not addressed, the program crashes with an error message that is ____ dependent.

A) code
B) computer
C) platform
D) IDE
Question
The try block is followed by one or more ____ blocks.

A) throw
B) finally
C) do
D) catch
Question
C++ provides all the exception classes you will ever need.
Question
One of the typical ways of dealing with exceptions is to use an if statement.
Question
The heading of a try block can contain ellipses in place of a parameter.
Question
Which of the following statements throws a valid exception in C++?

A) throw.function();
B) throw 2;
C) throws str;
D) 4 throw;
Question
An exception is an occurrence of an undesirable situation that can be detected during program compilation.
Question
In a sequence of try/catch blocks, the last catch block of that sequence should be ____.

A) catch(...){ }
B) catch(int x){ }
C) catch(str){ }
D) catch(exception){}
Question
All derived classes of the class exception override the function ____________________ to issue their own error messages.
Question
The logic_error and runtime_error classes are defined in the header file ____.

A) stdex
B) stdlib
C) stdexcept
D) exception
Question
The class ____ is designed to deal with errors that can be detected only during program execution.

A) error
B) exception
C) runtime_error
D) logic_error
Question
A(n) ____________________ block specifies the type of exception it can catch and contains an exception handler.
Question
Throwing an exception is typically done using the ____________________ statement.
Question
Which of the following statements creates a new exception class?

A) class myClass {};
B) class myClass {} implements exception;
C) class myExceptionClass {} extends exception;
D) class myExceptionClass {} throws exception;
Question
In C++, throw is a(n) ____________________ word.
Question
If you want to include members in your exception class, you typically include the function ____.

A) that
B) this
C) log
D) what
Question
Which of the following options should you choose when an exception occurs in the program that analyzes an airline's ticketing transactions?

A) Terminate the program.
B) Include code in the program to recover from the exception.
C) Log the error and continue.
D) Include code in the header file.
Question
Suppose you have written a program that inputs data from a file. If the input file does not exist when the program executes, then you should choose which option?

A) Terminate the program.
B) Include code in the program to recover from the exception.
C) Log the error and continue.
D) Include code in the header file.
Question
Which of the following classes is derived from the class runtime_error?

A) bad_alloc
B) out_of_range
C) overflow_error
D) length_error
Question
The ____________________ of the catch block parameter specifies the type of exception that the catch block can catch.
Question
When an exception is thrown in a function, the function-call stack is ____ so that the exception can be caught in the next try/catch block.

A) destroyed
B) allocated
C) unbound
D) unwound
Question
The class ____ is designed to deal with illegal arguments used in a function call.

A) illegal_argument
B) bad_argument
C) invalid_call
D) invalid_argument
Question
To deal with logical errors in a program, such as a string subscript out of range or an invalid argument to a function call, several classes are derived from the class ____.

A) logic_error
B) logic_exception
C) runtime_error
D) exception
Question
The general syntax to rethrow an exception caught by a catch block is: ____ (in this case, the same exception is rethrown).

A) rethrow;
B) throw;
C) rethrow exception;
D) throw exception;
Question
The class ____ is the base of the classes designed to handle exceptions.

A) class
B) exception
C) logic_error
D) runtime_error
Question
The function ____ returns a string containing an appropriate message.

A) where
B) what
C) when
D) log
Question
When an exception is thrown, if the program does not handle the exception, then the function ____ is called to terminate the program.

A) log
B) what
C) terminate
D) close
Question
If the operator new cannot allocate memory space, this operator throws a(n) ____________________ exception.
Question
The class ____________________ deals with the string subscript out of range error.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/42
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 14: Exception Handling
1
To use the assert function in your program, you should include the statement ____.

A) #include
B) #include
C) #include
D) #include
B
2
The order of the catch blocks does not affect the program.
False
3
An object that is being thrown cannot be an anonymous object.
False
4
Which of the following is a valid C++ statement?

A) assert(0 = divisor);
B) assert(divisor != 0);
C) assert(divisor 0);
D) assert(divisor is 0);
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
5
In C++, any class can be considered an exception class.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
6
A catch block can have, at most, ____ catch block parameter(s).

A) zero
B) one
C) two
D) three
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
7
The function ____ can check whether an expression meets the required conditions; if the conditions are not met, it terminates the program.

A) check
B) look
C) assert
D) what
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
8
The statements that may generate an exception are placed in a ____ block.

A) throw
B) finally
C) try
D) catch
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
9
Which of the following blocks is designed to catch any type of exception?

A) catch(){ }
B) catch(...){ }
C) catch(*){ }
D) catch(exception){ }
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
10
If the catch block with an ellipses (in the heading) is needed, then it should be the first catch block in a sequence of try/catch blocks.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
11
If no exception is thrown in a try block, all catch blocks associated with that try block are ignored.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
12
A(n) ____ is an occurrence of an undesirable situation that can be detected during program execution.

A) crash
B) exception
C) misfire
D) bug
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
13
A catch block specifies the type of exception it can catch and immediately terminates the program.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
14
When division by zero occurs and the problem is not addressed, the program crashes with an error message that is ____ dependent.

A) code
B) computer
C) platform
D) IDE
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
15
The try block is followed by one or more ____ blocks.

A) throw
B) finally
C) do
D) catch
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
16
C++ provides all the exception classes you will ever need.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
17
One of the typical ways of dealing with exceptions is to use an if statement.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
18
The heading of a try block can contain ellipses in place of a parameter.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following statements throws a valid exception in C++?

A) throw.function();
B) throw 2;
C) throws str;
D) 4 throw;
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
20
An exception is an occurrence of an undesirable situation that can be detected during program compilation.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
21
In a sequence of try/catch blocks, the last catch block of that sequence should be ____.

A) catch(...){ }
B) catch(int x){ }
C) catch(str){ }
D) catch(exception){}
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
22
All derived classes of the class exception override the function ____________________ to issue their own error messages.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
23
The logic_error and runtime_error classes are defined in the header file ____.

A) stdex
B) stdlib
C) stdexcept
D) exception
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
24
The class ____ is designed to deal with errors that can be detected only during program execution.

A) error
B) exception
C) runtime_error
D) logic_error
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
25
A(n) ____________________ block specifies the type of exception it can catch and contains an exception handler.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
26
Throwing an exception is typically done using the ____________________ statement.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following statements creates a new exception class?

A) class myClass {};
B) class myClass {} implements exception;
C) class myExceptionClass {} extends exception;
D) class myExceptionClass {} throws exception;
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
28
In C++, throw is a(n) ____________________ word.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
29
If you want to include members in your exception class, you typically include the function ____.

A) that
B) this
C) log
D) what
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following options should you choose when an exception occurs in the program that analyzes an airline's ticketing transactions?

A) Terminate the program.
B) Include code in the program to recover from the exception.
C) Log the error and continue.
D) Include code in the header file.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
31
Suppose you have written a program that inputs data from a file. If the input file does not exist when the program executes, then you should choose which option?

A) Terminate the program.
B) Include code in the program to recover from the exception.
C) Log the error and continue.
D) Include code in the header file.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following classes is derived from the class runtime_error?

A) bad_alloc
B) out_of_range
C) overflow_error
D) length_error
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
33
The ____________________ of the catch block parameter specifies the type of exception that the catch block can catch.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
34
When an exception is thrown in a function, the function-call stack is ____ so that the exception can be caught in the next try/catch block.

A) destroyed
B) allocated
C) unbound
D) unwound
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
35
The class ____ is designed to deal with illegal arguments used in a function call.

A) illegal_argument
B) bad_argument
C) invalid_call
D) invalid_argument
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
36
To deal with logical errors in a program, such as a string subscript out of range or an invalid argument to a function call, several classes are derived from the class ____.

A) logic_error
B) logic_exception
C) runtime_error
D) exception
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
37
The general syntax to rethrow an exception caught by a catch block is: ____ (in this case, the same exception is rethrown).

A) rethrow;
B) throw;
C) rethrow exception;
D) throw exception;
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
38
The class ____ is the base of the classes designed to handle exceptions.

A) class
B) exception
C) logic_error
D) runtime_error
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
39
The function ____ returns a string containing an appropriate message.

A) where
B) what
C) when
D) log
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
40
When an exception is thrown, if the program does not handle the exception, then the function ____ is called to terminate the program.

A) log
B) what
C) terminate
D) close
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
41
If the operator new cannot allocate memory space, this operator throws a(n) ____________________ exception.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
42
The class ____________________ deals with the string subscript out of range error.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 42 flashcards in this deck.