terminate() function

This is a discussion on terminate() function within the C++ Programming forums, part of the General Programming Boards category; Which of the following options describe the functions of an overridden terminate() function? A. It performs the desired cleanup and ...

  1. #1
    Spam is Good
    Join Date
    Jan 2009
    Location
    In a cave on Mars
    Posts
    37

    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.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    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...
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    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.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21