Answer the following statements true (T) or false (F)
1. A program can continue to run after an exception has been thrown and caught.
2. A function uses an exception specification that includes only int, but an exception of type double is thrown. A catch block is provided that catches a double, so things proceed properly.
3. A function does not have an exception specification at all, so exceptions are prohibited.
4. The exception specification for a function has no effect on an exception that is caught within the function.
5. Suppose an exception of type E is thrown in a function but not listed in the exception specification, and is not caught in the function. The exception will be caught in a calling function that has a catch block that declares an exception of that type.
1. True
To see that this is true, consider the following scenario. You are saving a document to a floppy disk, but the floppy drive door is not closed. An exception is thrown. A message sent from the catch statement tells you to close the drive door. You do so. The program (continuing) calls the output routine again to save your document.
2. False
Exception specifications specify the exceptions that might be thrown. If an exception is thrown that is not in the specification will cause unexpected() to be called. By default, unexpected() calls terminate(), which by default, calls abort() to terminate the program. At least this is what the standard says, but some compilers do not follow the standard in this regard.
3. False
A function declared without an exception specification is assumed to throw every exception. If there is no specification, then all exceptions are allowed. Contrast this with an exception specification that has an empty throw list, as in void f() throw()where no exceptions should be thrown.
4. True
The exception specification (or throw list) is to name exceptions that are propagated from the function to the function’s caller.
5. False
If such an exception is thrown, it will not be caught by any catch block in the program. Rather, the unexpected() function will call that will terminate your program unless you do something with set_unexpected or set_terminate (not treated in the text.)
You might also like to view...
When working with SmartArt Graphic types, a ________ illustrates connections.
a. Relationship b. Matrix c. Pyramid d. Picture
The user interacts with the operating system through the use of a GUI
Indicate whether the statement is true or false