Special Members and Exceptions


Two functions that are used by the exception management runtime are terminate() and unexpected(). Their role is the subject of this section.

The Function terminate()

The function void terminate()is called when:

The default action of the function void terminate() is to call the function abort() - which terminates the thread. The action of the function terminate() may be altered by the function set_terminate, whose declaration is as follows.

typedef void (*functionTerminate)();
functionTerminate set_terminate(functionTerminate);

The function set_terminate returns a pointer to the previous termination function. The first time set_terminate is called it returns the default termination function (which is abort()). Any function supplied to set_terminate must not attempt to continue processing; rather, it must terminate the thread.

The Function unexpected()

The function void unexpected()is called when a function throws an exception which it is not authorized to throw (see the topic of exception specifications). The default action of the function unexpected() is to call the function terminate(). The action of the function unexpected() may be altered by the function set_unexpected, whose declaration is as follows.

typedef void (*functionUnexpected)();
functionUnexpected set_unexpected(functionUnexpected);

The function set_unexpected returns a pointer to the previous 'unexpected' function. The first time set_unexpected is called it returns a pointer to the function void terminate().