CSCI 361 Chapter 16
true
1. The following function does not throw any unhandled exceptions void f1( ) throw ( );
a. throw and catch can be used like gotos
1. 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
true
10. The catch block is the group of statements that handle an exception.
c. catches all exceptions
10. 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
b. has only a default constructor
11. 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
b. it may be caught in that function
12. 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. not catch the exception in the function
13. 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. the function definition and declaration should have a throw list
14. 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
d. void f1( ) thaw (a,b);
15. Which of the following function declaration correctly specifies that two types of exceptions are thrown? a. void f1(exception a, exception b); b. void f1( ) exception (a;b); c. void f1( ) throw a, throw b; d. void f1( ) thaw (a,b);
c. the function will cause the program to exit
16. 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
b. have an exception specification that is a subset of the exception specification of the base class B
17. 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
b. encompass the function call
18. 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
c. bad_alloc
19. Which type of exception is thrown if a call to the new operator fails? a. ArithmeticError b. DivideByZero c. bad_alloc d. MemoryError
false
2. Functions that might throw an exception must have a throw list.
b. the try block
2. 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
d. None of the above
20. Which of the following code fragments are illegal? a. try { try { //other code here } catch(int e) { //code here } } catch(float e) { //code here } b. try { //code here } catch(int e) { //code here try { //code here } catch(string e) { } } c. All of the above d. None of the above
b. a derived class exception can be passed to an exception parameter of the base class
21. 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
e. none of the above
22. 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
b. only when you can not handle the exception with simpler control structures
23. 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
false
3. Functions may potentially throw at most one exception.
a. the catch block
3. 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
false
4. If a function throws an exception, it must be caught inside that function.
b. throw
4. When an unusual situation or error occurs, then the ________ statement is executed. a. try b. throw c. error d. exiting
b. all integer exceptions
5. 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
true
5. It is legal to have a catch block with no parameter.
false
6. In a try block, the throw statement is always executed.
a. execution of the try block stops
6. 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
false
7. The catch block is a function.
a. identifies what type of exceptions are caught
7. 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
false
8. The braces are not necessary on a try block.
c. a try block
8. The throw statement is enclosed in a. a catch block b. a throw block c. a try block d. quotes
e. all of the above
9. A throw statement can throw a. an integer exception b. a float exception c. a bool exception d. an exception of any data type e. all of the above f. none of the above
true
9. The throw statement passes a value to the catch block.