All objects thrown by components of the standard library are derived from this class. Therefore, all standard exceptions can be caught by catching this type.
It is declared as:
| 1 2 3 4 5 6 7 8 |
|
Some classes derived from exception are: bad_alloc, bad_cast, bad_exception, bad_typeid, logic_error, runtime_error, ios_base::failure...
Members
- default constructor: exception () throw();
- Constructs an object.
- copy constructor: exception (const exception&) throw();
and assignment: exception& operator= (const exception&) throw(); - Copies an exception object (the results of calling member what on the copy are implementation-specific).
- destructor: virtual ~exception() throw();
- Destroys the object.
- const char* what() const throw();
- Returns a null terminated character sequence containing a generic description of the exception.
Both the wording of such description and the character width are implementation-defined.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Possible output:
exception caught: St10bad_typeid |
