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
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/47
Play
Full screen (f)
Deck 16: Exception Handling
1
If a function throws an exception, it must be caught inside that function.
False
2
The catch block
catch ...)
is known as the ______________.
catch ...)
is known as the ______________.
default catch block
3
Functions may potentially throw at most one exception.
False
4
The catch block is a function.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
5
The catch block is the group of statements that handle an exception.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
6
Exception handling is used to _____________.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
7
The braces are not necessary on a try block.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
8
C++ signals an error or unusual situation by __________.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
9
A throw statement passes which type of value to the catch block?
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
10
The throw statement passes a value to the catch block.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
11
Functions that might throw an exception must have a throw list.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
12
If a function does not have an exception specification, then the function can thaw _______ exceptions.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
13
The following function does not throw any unhandled exceptions
void f1 ) throw );
void f1 ) throw );
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
14
The catch block is also known as the ___________.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
15
The following catch block catches all __________ exceptions.
catch string e)
{
}
catch string e)
{
}
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
16
If no exception is thrown, then the _________ is ignored.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
17
If a function throws an exception and does not catch it, then the function definition and declaration should have _______.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
18
In a try block, the throw statement is always executed.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
19
It is legal to have a catch block with no parameter.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
20
If a throw list has multiple exceptions listed, they are separated by _________.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
21
The following class definition
Class MyError
{};
A) has no member functions or member data
B) has only a default constructor
C) is illegal
D) A and B
Class MyError
{};
A) has no member functions or member data
B) has only a default constructor
C) is illegal
D) A and B
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
22
When a throw statement is executed,
A) execution of the try block stops
B) execution of the throw block stops
C) the program always exits
D) execution of the catch block stops
A) execution of the try block stops
B) execution of the throw block stops
C) the program always exits
D) execution of the catch block stops
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
23
The parameter in the catch statement
A) identifies what type of exceptions are caught
B) identifies the different number of exceptions that can be caught
C) makes the catch block a function
D) must always be an e
A) identifies what type of exceptions are caught
B) identifies the different number of exceptions that can be caught
C) makes the catch block a function
D) must always be an e
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
24
If the following function throws an unhandled exception, what happens?
void f1);
void f1);
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
25
Given the following function definition, what happens if the function throws the exception?
Void f1 ) throw double)
{
If //some code here)
Throw 12;
}
A) the 12 will be converted to 12.0
B) the function will throw an integer exception which is passed to the calling code.
C) the function will cause the program to exit
D) this code has a syntax error
Void f1 ) throw double)
{
If //some code here)
Throw 12;
}
A) the 12 will be converted to 12.0
B) the function will throw an integer exception which is passed to the calling code.
C) the function will cause the program to exit
D) this code has a syntax error
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
26
If the following function will throw a string exception, then
Void myFunction );
A) the function definition and declaration should have a throw list
B) the function definition, but not the declaration should have a throw list
C) the function should have an empty throw list.
D) all of the above
Void myFunction );
A) the function definition and declaration should have a throw list
B) the function definition, but not the declaration should have a throw list
C) the function should have an empty throw list.
D) all of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
27
When an unusual situation or error occurs, then the ________ statement is executed.
A) try
B) throw
C) error
D) exiting
A) try
B) throw
C) error
D) exiting
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
28
A catch block that expects an integer argument will catch
A) all exceptions
B) all integer exceptions
C) any exception value that can be coerced into an integer
D) none of the above
A) all exceptions
B) all integer exceptions
C) any exception value that can be coerced into an integer
D) none of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
29
The block of code that checks if an unusual situation or error occurs is called
A) the catch block
B) the try block
C) a function
D) an error block
A) the catch block
B) the try block
C) a function
D) an error block
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
30
Can the following function throw any unhandled exceptions?
void f1 );
void f1 );
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
31
If a function throws an exception,
A) it must be caught in that function.
B) it may be caught in that function
C) it causes a syntax error
D) it can only be a non-numeric exception.
A) it must be caught in that function.
B) it may be caught in that function
C) it causes a syntax error
D) it can only be a non-numeric exception.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
32
The block of code that handles an exception is called
A) the catch block
B) the try block
C) a function
D) an error block
A) the catch block
B) the try block
C) a function
D) an error block
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
33
If you have a function that might throw an exception and some programs that use that function might want to handle that exception differently, you should
A) not catch the exception in the function
B) throw an integer exception
C) never throw an exception in this function
D) none of the above
A) not catch the exception in the function
B) throw an integer exception
C) never throw an exception in this function
D) none of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
34
The following catch statement
Catch...)
A) is illegal
B) catches only numeric exceptions
C) catches all exceptions
D) should be the first catch block if multiple catch statements are present
Catch...)
A) is illegal
B) catches only numeric exceptions
C) catches all exceptions
D) should be the first catch block if multiple catch statements are present
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
35
If some part of your program or any library functions that are called) throw an exception, then if this exception is not handled in your code, your program will _____.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
36
If a function throw list specifies a base class type, then the function may also throw an exception of the ________ class type.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
37
Which of the following function declaration correctly specifies that two types of exceptions are thrown?
A) void f1exception a, exception b);
B) void f1 ) exception a;b);
C) void f1 ) throw a, throw b;
D) void f1 ) thaw a,b);
A) void f1exception a, exception b);
B) void f1 ) exception a;b);
C) void f1 ) throw a, throw b;
D) void f1 ) thaw a,b);
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
38
The throw statement is enclosed in
A) a catch block
B) a throw block
C) a try block
D) quotes
A) a catch block
B) a throw block
C) a try block
D) quotes
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
39
Which of the following is not a valid reason for using exception handling?
A) throw and catch can be used like gotos
B) the procedure for handling an error depends on the situation
C) need to handle built in exceptions
D) none of the above
A) throw and catch can be used like gotos
B) the procedure for handling an error depends on the situation
C) need to handle built in exceptions
D) none of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
40
If the following function throws an unhandled exception, what happens?
void f1) throws );
void f1) throws );
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
41
Which of the following would be a good reason for using inherited exception classes?
A) a base class exception can be passed to an exception parameter of the derived class
B) a derived class exception can be passed to an exception parameter of the base class
C) a base class exception parameter can be passed any type of exception
D) all of the above
A) a base class exception can be passed to an exception parameter of the derived class
B) a derived class exception can be passed to an exception parameter of the base class
C) a base class exception parameter can be passed any type of exception
D) all of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
42
If a function will possibly throw an unhandled exception, the try block should
A) be in the function definition
B) encompass the function call
C) be in the catch block
D) not be used
A) be in the function definition
B) encompass the function call
C) be in the catch block
D) not be used
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
43
A class that is used for exceptions is declared
A) differently from other classes
B) specialized only for exceptions
C) may not have objects declared of that class
D) all of the above
E) none of the above
A) differently from other classes
B) specialized only for exceptions
C) may not have objects declared of that class
D) all of the above
E) none of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
44
If class A is derived from class B, and a virtual function in class B throws an exception, then the overridden version of that function in class A must
A) not throw any exceptions
B) have an exception specification that is a subset of the exception specification of the base class B
C) not throw any exceptions that the function in class B might throw
D) all of the above
A) not throw any exceptions
B) have an exception specification that is a subset of the exception specification of the base class B
C) not throw any exceptions that the function in class B might throw
D) all of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
45
You should use exception handling
A) in all your programs
B) only when you can not handle the exception with simpler control structures
C) only when you use classes
D) in every function
A) in all your programs
B) only when you can not handle the exception with simpler control structures
C) only when you use classes
D) in every function
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
46
Which of the following code fragments are illegal?
A) try {
Try
{
//other code here
}
Catchint e)
{
//code here
}
}
Catchfloat e)
{
//code here
}
B) try {
//code here
}
Catchint e)
{
//code here
Try
{
//code here
}
Catchstring e)
{
}
}
C) All of the above
D) None of the above
A) try {
Try
{
//other code here
}
Catchint e)
{
//code here
}
}
Catchfloat e)
{
//code here
}
B) try {
//code here
}
Catchint e)
{
//code here
Try
{
//code here
}
Catchstring e)
{
}
}
C) All of the above
D) None of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
47
Which type of exception is thrown if a call to the new operator fails?
A) ArithmeticError
B) DivideByZero
C) bad_alloc
D) MemoryError
A) ArithmeticError
B) DivideByZero
C) bad_alloc
D) MemoryError
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck