[Previous] [Contents] [Next]

<exception>


Include the standard header <exception> to define several types and functions related to the handling of exceptions.

        // DECLARATIONS
class exception;
class bad_exception;

        // FUNCTIONS
typedef void (*terminate_handler)();
typedef void (*unexpected_handler)();
terminate_handler
    set_terminate(terminate_handler pnew) throw();
unexpected_handler
    set_unexpected(unexpected_handler pnew) throw();
void terminate();
void unexpected();
bool uncaught_exception();
        // END OF DECLARATIONS

bad_exception

class bad_exception
    : public exception {
    };

The class describes an exception that can be thrown from an unexpected handler. The value returned by what() is an implementation-defined C string. None of the member functions throw any exceptions.

exception

class exception {
public:
    exception() throw();
    exception(const exception& right) throw();
    exception& operator=(const exception& right) throw();
    virtual ~exception() throw();
    virtual const char *what() const throw();
    };

The class serves as the base class for all exceptions thrown by certain expressions and by the Standard C++ library. The C string value returned by what() is left unspecified by the default constructor, but may be defined by the constructors for certain derived classes as an implementation-defined C string.

None of the member functions throw any exceptions.

set_terminate

terminate_handler
    set_terminate(terminate_handler pnew) throw();

The function establishes a new terminate handler as the function *pnew. Thus, pnew must not be a null pointer. The function returns the address of the previous terminate handler.

set_unexpected

unexpected_handler
    set_unexpected(unexpected_handler pnew) throw();

The function establishes a new unexpected handler as the function *pnew. Thus, pnew must not be a null pointer. The function returns the address of the previous unexpected handler.

terminate

void terminate();

The function calls a terminate handler, a function of type void (). If terminate is called directly by the program, the terminate handler is the one most recently set by a call to set_terminate. If terminate is called for any of several other reasons during evaluation of a throw expression, the terminate handler is the one in effect immediately after evaluating the throw expression.

A terminate handler may not return to its caller. At program startup, the terminate handler is a function that calls abort().

terminate_handler

typedef void (*terminate_handler)();

The type describes a pointer to a function suitable for use as a terminate handler.

uncaught_exception

bool uncaught_exception();

The function returns true only if a thrown exception is being currently processed. Specifically, it returns true after completing evaluation of a throw expression and before completing initialization of the exception declaration in the matching handler or calling unexpected as a result of the throw expression.

unexpected

void unexpected();

The function calls an unexpected handler, a function of type void (). If unexpected is called directly by the program, the unexpected handler is the one most recently set by a call to set_unexpected. If unexpected is called when control leaves a function by a thrown exception of a type not permitted by an exception specification for the function, as in:

void func() throw()   // function may throw no exceptions
    {throw "bad"; }   // throw calls unexpected()

the unexpected handler is the one in effect immediately after evaluating the throw expression.

An unexpected handler may not return to its caller. It may terminate execution by:

At program startup, the unexpected handler is a function that calls terminate().

unexpected_handler

typedef void (*unexpected_handler)();

The type describes a pointer to a function suitable for use as an unexpected handler.


See also the Table of Contents and the Index.

Copyright © 1992-2002 by P.J. Plauger. All rights reserved.

[Previous] [Contents] [Next]