Chapter 14 Flashcards

1
Q

True or false:
An exception is an occurrence of an undesirable situation that can be detected during program compilation.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or false:
One of the typical ways of dealing with exceptions is to use an if statement.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

True or false:
The heading of a try block can contain ellipses in place of a parameter.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True or false:
A catch block specifies the type of exceptions it can catch and immediately terminates the program.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

True or false:
If no exception is thrown in a try block, all catch blocks associated with that try block are ignored.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True or false:
An object that is being thrown cannot be an anonymous object.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

True or false:
The order of the catch blocks does not affect the program

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or false:
If the catch block with an ellipses in the heading is needed, then it should be in the first catch block in a sequence of try/catch blocks.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

True or false:
C++ provides all the exception classes you will ever need.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

True or false:
In C++, any class can be considered an exception class.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

An _______ is an occurrence of an undesirable situation that can be detected during program execution.

A

exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The function _____ can check whether an expression meets the required conditions; if the conditions are not met, it terminates the program.

A

assert

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When division by zero occurs and the problem is not addressed, the program crashes with an error message that is _____ dependent.

A

IDE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

To use the assert function in your program, you should include the statement _______

A

include <cassert></cassert>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The statements that may generate an exception are placed in a ______ block.

A

try

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which of the following blocks is designed to catch any type of exception?

A

catch(…){}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The try block is followed by one or more _____ blocks.

A

catch

16
Q

The function ______ returns a string containing an appropriate message.

A

what

17
Q

A catch block can have, at most, _____ catch block parameter(s).

A

one

17
Q

Which of the following statements throws a valid exception in C++?

A

throw 2;

18
Q

The class _______ is the base of the classes designed to handle exceptions.

A

exception

18
Q

In a sequence of try/catch blocks, the last catch block of that sequence should be _______.

A

catch(…){}

19
Q

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

20
Q

The class _____ is designed to deal with illegal arguments used in a function call.

A

invalid_argument

21
Q

Which of the following classes is derived from the class runtime_error?

A

overflow_error

22
Q

The class ____ is designed to deal with errors that can be detected only during program execution.

A

runtime_error

23
Q

The logic_error and runtime_error classes are defined with the header file _______.

A

stdexcept

24
Q

Which of the following statements creates a new exception class?

A

class myClass{};

25
Q

If you want to include members in your exception class, you typically include the function ________

A

what

26
Q

The general syntax to rethrow an exception caught by a catch block is: _______

A

throw;

27
Q

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

28
Q

Which of the following options should you choose when an exception occurs in the program that analyzes an airline’s ticketing transactions?

A

log the error and continue

29
Q

When an exception is thrown, if the program does not handle the exception, then the function ______ is called to terminate the program.

A

terminate

30
Q

A(n) _______ block specifies the type of exception it can catch and contains an exception handler.

A

catch

31
Q

The __________ of the catch block parameter specifies the type of exception that the catch block can catch.

A

data type

32
Q

Throwing an exception is typically done using the ______ statement.

A

throw

33
Q

In C++, throw is a(n) _________ word.

A

reserved

34
Q

All derived classes of the class exception override the function ______ to issue their own error messages.

A

what

35
Q

The class _________ deals with the string subscript out of range error.

A

out_of_range

36
Q

If the operator new cannot allocate memory space, this operator throws a(n) _________ exception.

A

bad_alloc