-
terminate() function
Which of the following options describe the functions of an overridden terminate() function?
A. It performs the desired cleanup and shutdown processing, and then returns an error status value to the calling function.
B. It performs the desired cleanup and shutdown processing, and then calls abort() or exit().
C. It performs the desired cleanup and shutdown processing, and if it has restored the system to a stable state, it returns a value of "-1" to indicate successful recovery.
D. It performs the desired cleanup and shutdown processing, and then throws a termination_exception.
E. It performs the desired cleanup and shutdown processing, and then calls the unexpected() handler.
I really don't know much about the terminate() function as I've never heard of it till now. The only thing I know is what I've read at http://publib.boulder.ibm.com/infoce...ef/cplr163.htm
Based on that link I see B as correct and the rest as incorrect.
Could someone else clarify my answer please.
-
It should be B, but in fact I can't imagine how you would do much clean-up in the terminate handler. How would a humble void(*)(void) function that you register with set_terminate know anything about the rest of the program (except perhaps globals) to do any clean-up?
The program just blew up entirely...
-
You're right, B is the only correct answer. terminate() must never return, either normally or abnormally (via an exception). In fact, calling exit() is pretty risky too, unless you can guarantee that the program is in a state where the exit handlers can safely run (remember, terminate() is called for really serious issues!). abort() is usually the better choice. In fact, I've never seen any need to install a temination handler at all.