exception(3C++)


exception -- exception handling

Synopsis

   #include <exception> 
   

namespace std { class exception; class bad_exception;

typedef void (*unexpected_handler)(); unexpected_handler set_unexpected(unexpected_handler f) throw(); <B>void unexpected(); typedef void (*terminate_handler)(); terminate_handler set_terminate(terminate_handler f) throw(); void terminate(); bool uncaught_exception(); }

Description

The header exception defines several types and functions related to the handling of exceptions in a C++ program.

Classes

exception
   namespace std { 
     class exception { 
     public: 
       exception() throw(); 
       exception(const exception&) throw(); 
       exception& operator=(const exception&) throw(); 
       virtual ~exception() throw(); 
       virtual const char* what() const throw(); 
     }; 
   } 
The class exception defines the base class for the types of objects thrown as exceptions by C++ Standard library components, and certain expressions, to report errors detected during program execution.

exception() throw();
Effects: Constructs an object of class exception.
Notes: Does not throw any exceptions.

exception(const exception&) throw();

exception& operator=(const exception&) throw();
Effects: Copies an exception object.

virtual ~exception() throw();
Effects: Destroys an object of class exception.
Notes: Does not throw any exceptions.

virtual const char* what() const throw();
Returns: The string std::exception.

bad_exception
   namespace std { 
     class bad_exception : public exception { 
     public: 
       bad_exception() throw(); 
       bad_exception(const bad_exception&) throw(); 
       bad_exception& operator=(const bad_exception&) throw(); 
       virtual ~bad_exception() throw(); 
       virtual const char* what() const throw(); 
     }; 
   } 
The class bad_exception defines the type of objects thrown when an unexpected() handler throws or rethrows an exception that the violated exception specification does not allow, but the violated exception specification does include the std::bad_exception type.

bad_exception() throw();
Effects: Constructs an object of class bad_exception.

bad_exception(const bad_exception&) throw();

bad_exception& operator=(const bad_exception&) throw();
Effects: Copies an object of class bad_exception.

virtual const char* what() const throw();
Returns: The string std::bad_exception.

Functions

typedef void (*unexpected_handler)();
The type of a handler function to be called by unexpected when a function attempts to throw an exception not listed in its exception-specification.
Required behavior: an unexpected_handler either throws an exception or terminates execution of the program without returning to the caller. An unexpected_handler may perform any of the following: Default behavior: The implementation's default unexpected_handler calls terminate.

unexpected_handler set_unexpected(unexpected_handler f) throw();
Effects: Establishes the function designated by f as the current unexpected_handler.
Requires: f shall not be a null pointer.
Returns: The previous unexpected_handler.

void unexpected();
Called by the implementation when a function exits via an exception not allowed by its exception-specification. May also be called directly by the program.
Effects: Calls the unexpected_handler function in effect immediately after evaluating the throw-expression, if called by the implementation, or calls the current unexpected_handler, if called by the program.

typedef void (*terminate_handler)();
The type of a handler function to be called by terminate when terminating exception processing.
Required behavior: A terminate_handler shall terminate execution of the program without returning to the caller.
Default behavior: The implementation's default terminate_handler calls abort.

terminate_handler set_terminate(terminate_handler f) throw();
Effects: Establishes the function designated by f as the current handler function for terminating exception processing.
Requires: f must not be a null pointer.
Returns: The previous terminate_handler.

void terminate();
Called when exception handling must be abandoned for any of several reasons. May also be called directly by the program.
Effects: Calls the terminate_handler function in effect immediately after evaluating the throw-expression, if called by the implementation, or calls the current terminate_handler function, if called by the program.

bool uncaught_exception();
Returns: true after completing evaluation of a throw-expression until either completing initialization of the exception-declaration in the matching handler or after entering terminate for any reason other than an explicit call to terminate. Note that this includes stack unwinding.
Notes: When uncaught_exception is true, throwing an exception can result in a call of terminate.

30 January 1998
© 1998 The Santa Cruz Operation, Inc. All rights reserved.