DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

exception(C++std)


bad_exception , exception , set_terminate , set_unexpected , terminate , terminate_handler , uncaught_exception , unexpected , unexpected_handler - defines several functions that control exception handling

Synopsis

   exceptionnamespace std {
   class exception;
   class bad_exception;

           // FUNCTIONS
   typedef void (*terminate_handler)();
   typedef void (*unexpected_handler)();
   terminate_handler
       set_terminate(terminate_handler ph) throw();
   unexpected_handler
       set_unexpected(unexpected_handler ph) throw();
   void terminate();
   void unexpected();
   bool uncaught_exception();
   );
   

Description

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

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& rhs) throw();
       exception& operator=(const exception& rhs) 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 ph) throw();

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

set_unexpected

   unexpected_handler
       set_unexpected(unexpected_handler ph) throw();

The function establishes a new unexpected handler as the function *ph. Thus, ph 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 f() 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.

References


18 February 2000
© 2000 The Santa Cruz Operation, Inc. All rights reserved.

Copyright © 1992-1996 by P.J. Plauger. Portions derived from work copyright © 1994 by Hewlett-Packard Company. All rights reserved.