1 This clause describes the function signatures that are called implicitly, and the types of objects generated implicitly, during the execution of some C++ programs. It also describes the headers that declare these function signatures and define any related types.
2 The following subclauses describe common type definitions used throughout the library, characteristics of the predefined types, functions supporting start and termination of a C++ program, support for dynamic memory management, support for dynamic type identification, support for exception processing, and other runtime support, as summarized in Table 14:
Table 14---Language support library summary |
_ _______________________________________________ _ Subclause Header(s) _ _______________________________________________ _______________________________________________ _ 18.1 Types <cstddef> _______________________________________________ <limits> 18.2 Implementation properties <climits> _ <cfloat> _______________________________________________ _ 18.3 Start and termination <cstdlib> _______________________________________________ _ 18.4 Dynamic memory management <new> _______________________________________________ _ 18.5 Type identification <typeinfo> _______________________________________________ _ 18.6 Exception handling <exception> _______________________________________________ <cstdarg> <csetjmp> 18.7 Other runtime support <ctime> <csignal> _ <cstdlib> _______________________________________________ |
1 Common definitions.
2 Header <cstddef> (Table 15):
Table 15---Header <cstddef> synopsis |
_ ____________________________________ _ Kind Name(s) ____________________________________ _ Macros: NULL offsetof ____________________________________ _ Types: ptrdiff_t size_t ____________________________________ |
3 The contents are the same as the Standard C library header <stddef.h>, with the following changes:
4 The macro NULL is an implementation-defined C++ null pointer constant in this International Standard (4.10).180)
5 The macro offsetof accepts a restricted set of type arguments in this International Standard. type shall be a POD structure or a POD union (clause 9). The result of applying the offsetof macro to a field that is a static data member or a function member is undefined. SEE ALSO: subclause 5.3.3, Sizeof, subclause 5.7, Additive operators, subclause 12.5, Free store, and ISO C subclause 7.1.6.
180) Possible definitions include 0 and 0L, but not (void*)0. [back to text]
1 The headers <limits>, <climits>, and <cfloat> supply characteristics of implementationdependent fundamental types (3.9.1).
1 The numeric_limits component provides a C++ program with information about various properties of the implementation's representation of the fundamental types.
2 Specializations shall be provided for each fundamental type, both floating point and integer, including bool. The member is_specialized shall be true for all such specializations of numeric_limits.
3 For all members declared static const in the numeric_limits template, specializations shall define these values in such a way that they are usable as integral constant expressions.
4 Non-fundamental standard types, such as complex<T> (26.2.2), shall not have specializations. Header <limits> synopsis
namespace std { template<class T> class numeric_limits; enum float_round_style; enum float_denorm_style; template<> class numeric_limits<bool>; template<> class numeric_limits<char>; template<> class numeric_limits<signed char>; template<> class numeric_limits<unsigned char>; template<> class numeric_limits<wchar_t>; template<> class numeric_limits<short>; template<> class numeric_limits<int>; template<> class numeric_limits<long>; template<> class numeric_limits<unsigned short>; template<> class numeric_limits<unsigned int>; template<> class numeric_limits<unsigned long>; template<> class numeric_limits<float>; template<> class numeric_limits<double>; template<> class numeric_limits<long double>; }
namespace std { template<class T> class numeric_limits { public: static const bool is_specialized = false; static T min() throw(); static T max() throw(); static const int digits = 0; static const int digits10 = 0; static const bool is_signed = false; static const bool is_integer = false; static const bool is_exact = false; static const int radix = 0; static T epsilon() throw(); static T round_error() throw(); static const int min_exponent = 0; static const int min_exponent10 = 0; static const int max_exponent = 0; static const int max_exponent10 = 0; static const bool has_infinity = false; static const bool has_quiet_NaN = false; static const bool has_signaling_NaN = false; static const float_denorm_style has_denorm = denorm_absent; static const bool has_denorm_loss = false; static T infinity() throw(); static T quiet_NaN() throw(); static T signaling_NaN() throw(); static T denorm_min() throw(); static const bool is_iec559 = false; static const bool is_bounded = false; static const bool is_modulo = false; static const bool traps = false; static const bool tinyness_before = false; static const float_round_style round_style = round_toward_zero; }; }
1 The member is_specialized makes it possible to distinguish between fundamental types, which have specializations, and non-scalar types, which do not.
2 The default numeric_limits<T> template shall have all members, but with 0 or false values.
static T min() throw();
1 Minimum finite value.181)
2 For floating types with denormalization, returns the minimum positive normalized value.
3 Meaningful for all specializations in which is_bounded != false, or is_bounded == false && is_signed == false.
static T max() throw();
4 Maximum finite value.182)
5 Meaningful for all specializations in which is_bounded != false.
static const int digits;
6 Number of radix digits that can be represented without change.
7 For built-in integer types, the number of non-sign bits in the representation.
8 For floating point types, the number of radix digits in the mantissa.183)
static const int digits10;
9 Number of base 10 digits that can be represented without change.184)
10 Meaningful for all specializations in which is_bounded != false.
static const bool is_signed;
11 True if the type is signed.
12 Meaningful for all specializations.
static const bool is_integer;
13 True if the type is integer.
14 Meaningful for all specializations.
static const bool is_exact;
15 True if the type uses an exact representation. All integer types are exact, but not all exact types are integer. For example, rational and fixed-exponent representations are exact but not integer.
16 Meaningful for all specializations.
static const int radix;
17 For floating types, specifies the base or radix of the exponent representation (often 2).185)
18 For integer types, specifies the base of the representation.186)
19 Meaningful for all specializations.
static T epsilon() throw();
20 Machine epsilon: the difference between 1 and the least value greater than 1 that is representable.187)
21 Meaningful for all floating point types.
static T round_error() throw();
22 Measure of the maximum rounding error.188)
static const int min_exponent;
23 Minimum negative integer such that radix raised to the power of one less than that integer is a normalized floating point number.189)
24 Meaningful for all floating point types.
static const int min_exponent10;
25 Minimum negative integer such that 10 raised to that power is in the range of normalized floating point numbers.190)
26 Meaningful for all floating point types.
static const int max_exponent;
27 Maximum positive integer such that radix raised to the power one less than that integer is a representable finite floating point number.191)
28 Meaningful for all floating point types.
static const int max_exponent10;
29 Maximum positive integer such that 10 raised to that power is in the range of representable finite floating point numbers.192)
30 Meaningful for all floating point types.
static const bool has_infinity;
31 True if the type has a representation for positive infinity.
32 Meaningful for all floating point types.
33 Shall be true for all specializations in which is_iec559 != false.
static const bool has_quiet_NaN;
34 True if the type has a representation for a quiet (non-signaling) ``Not a Number.''193)
35 Meaningful for all floating point types.
36 Shall be true for all specializations in which is_iec559 != false.
static const bool has_signaling_NaN;
37 True if the type has a representation for a signaling ``Not a Number.''194)
38 Meaningful for all floating point types.
39 Shall be true for all specializations in which is_iec559 != false.
static const float_denorm_style has_denorm;
40 denorm_present if the type allows denormalized values (variable number of exponent bits)195), denorm_absent if the type does not allow denormalized values, and denorm_indeterminate if it is indeterminate at compile time whether the type allows denormalized values.
41 Meaningful for all floating point types.
static const bool has_denorm_loss;
42 True if loss of accuracy is detected as a denormalization loss, rather than as an inexact result.196)
static T infinity() throw();
43 Representation of positive infinity, if available.197)
44 Meaningful for all specializations for which has_infinity != false. Required in specializations for which is_iec559 != false.
static T quiet_NaN() throw();
45 Representation of a quiet ``Not a Number,'' if available.198)
46 Meaningful for all specializations for which has_quiet_NaN != false. Required in specializations for which is_iec559 != false.
static T signaling_NaN() throw();
47 Representation of a signaling ``Not a Number,'' if available.199)
48 Meaningful for all specializations for which has_signaling_NaN != false. Required in specializations for which is_iec559 != false.
static T denorm_min() throw();
49 Minimum positive denormalized value.200)
50 Meaningful for all floating point types.
51 In specializations for which has_denorm == false, returns the minimum positive normalized value.
static const bool is_iec559;
52 True if and only if the type adheres to IEC 559 standard.201)
53 Meaningful for all floating point types.
static const bool is_bounded;
54 True if the set of values representable by the type is finite.202) All built-in types are bounded, this member would be false for arbitrary precision types.
55 Meaningful for all specializations.
static const bool is_modulo;
56 True if the type is modulo.203) A type is modulo if it is possible to add two positive numbers and have a result that wraps around to a third number that is less.
57 Generally, this is false for floating types, true for unsigned integers, and true for signed integers on most machines.
58 Meaningful for all specializations.
static const bool traps;
59 true if trapping is implemented for the type.204)
60 Meaningful for all specializations.
static const bool tinyness_before;
61 true if tinyness is detected before rounding.205)
62 Meaningful for all floating point types.
static const float_round_style round_style;
63 The rounding style for the type.206)
64 Meaningful for all floating point types. Specializations for integer types shall return round_toward_zero.
181) Equivalent to CHAR_MIN, SHRT_MIN, FLT_MIN, DBL_MIN, etc. [back to text]182) Equivalent to CHAR_MAX, SHRT_MAX, FLT_MAX, DBL_MAX, etc. [back to text]
183) Equivalent to FLT_MANT_DIG, DBL_MANT_DIG, LDBL_MANT_DIG. [back to text]
184) Equivalent to FLT_DIG, DBL_DIG, LDBL_DIG. [back to text]
185) Equivalent to FLT_RADIX. [back to text]
186) Distinguishes types with bases other than 2 (e.g. BCD). [back to text]
187) Equivalent to FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON. [back to text]
188) Rounding error is described in ISO/IEC 10967-1 Language independent arithmetic Part 1 Section 5.2.8 and Annex A Rationale Section A.5.2.8 Rounding constants. [back to text]
189) Equivalent to FLT_MIN_EXP, DBL_MIN_EXP, LDBL_MIN_EXP. [back to text]
190) Equivalent to FLT_MIN_10_EXP, DBL_MIN_10_EXP, LDBL_MIN_10_EXP. [back to text]
191) Equivalent to FLT_MAX_EXP, DBL_MAX_EXP, LDBL_MAX_EXP. [back to text]
192) Equivalent to FLT_MAX_10_EXP, DBL_MAX_10_EXP, LDBL_MAX_10_EXP. [back to text]
193) Required by LIA-1. [back to text]
194) Required by LIA-1. [back to text]
195) Required by LIA-1. [back to text]
196) See IEC 559. [back to text]
197) Required by LIA-1. [back to text]
198) Required by LIA-1. [back to text]
199) Required by LIA-1. [back to text]
200) Required by LIA-1. [back to text]
201) International Electrotechnical Commission standard 559 is the same as IEEE 754. [back to text]
202) Required by LIA-1. [back to text]
203) Required by LIA-1. [back to text]
204) Required by LIA-1. [back to text]
205) Refer to IEC 559. Required by LIA-1. [back to text]
206) Equivalent to FLT_ROUNDS. Required by LIA-1. [back to text]
namespace std { enum float_round_style { round_indeterminate = -1, round_toward_zero = 0, round_to_nearest = 1, round_toward_infinity = 2, round_toward_neg_infinity = 3 }; }
1 The rounding mode for floating point arithmetic is characterized by the values:
namespace std { enum float_denorm_style { denorm_indeterminate = -1; denorm_absent = 0; denorm_present = 1; }; }
1 The presence or absence of denormalization (variable number of exponent bits) is characterized by the values:
1 All members shall be provided for all specializations. However, many values are only required to be meaningful under certain conditions (for example, epsilon() is only meaningful if is_integer is false). Any value that is not ``meaningful'' shall be set to 0 or false.
2 [Example:
---end example]namespace std { template<> class numeric_limits<float> { public: static const bool is_specialized = true; inline static float min() throw() { return 1.17549435E-38F; } inline static float max() throw() { return 3.40282347E+38F; } static const int digits = 24; static const int digits10 = 6; static const bool is_signed = true; static const bool is_integer = false; static const bool is_exact = false; static const int radix = 2; inline static float epsilon() throw() { return 1.19209290E-07F; } inline static float round_error() throw() { return 0.5F; } static const int min_exponent = -125; static const int min_exponent10 = - 37; static const int max_exponent = +128; static const int max_exponent10 = + 38; static const bool has_infinity = true; static const bool has_quiet_NaN = true; static const bool has_signaling_NaN = true; static const float_denorm_style has_denorm = denorm_absent; static const bool has_denorm_loss = false; inline static float infinity() throw() { return ...; } inline static float quiet_NaN() throw() { return ...; } inline static float signaling_NaN() throw() { return ...; } inline static float denorm_min() throw() { return min(); } static const bool is_iec559 = true; static const bool is_bounded = true; static const bool is_modulo = false; static const bool traps = true; static const bool tinyness_before = true; static const float_round_style round_style = round_to_nearest; }; }
1 Header <climits> (Table 16):
Table 16---Header <climits> synopsis |
_ __________________________________________________________________________ _ Type Name(s) __________________________________________________________________________ Values: CHAR_BIT INT_MAX LONG_MIN SCHAR_MIN UCHAR_MAX USHRT_MAX CHAR_MAX INT_MIN MB_LEN_MAX SHRT_MAX UINT_MAX _ CHAR_MIN LONG_MAX SCHAR_MAX SHRT_MIN ULONG_MAX __________________________________________________________________________ |
2 The contents are the same as the Standard C library header <limits.h>.
3 Header <cfloat> (Table 17):
Table 17---Header <cfloat> synopsis |
_ ________________________________________________________________________ _ Type Name(s) ________________________________________________________________________ Values: DBL_DIG DBL_MIN_EXP FLT_MIN_10_EXP LDBL_MAX_10_EXP DBL_EPSILON FLT_DIG FLT_MIN_EXP LDBL_MAX_EXP DBL_MANT_DIG FLT_EPSILON FLT_RADIX LDBL_MIN DBL_MAX FLT_MANT_DIG FLT_ROUNDS LDBL_MIN_10_EXP DBL_MAX_10_EXP FLT_MAX LDBL_DIG LDBL_MIN_EXP DBL_MAX_EXP FLT_MAX_10_EXP LDBL_EPSILON DBL_MIN FLT_MAX_EXP LDBL_MANT_DIG _ DBL_MIN_10_EXP FLT_MIN LDBL_MAX ________________________________________________________________________ |
4 The contents are the same as the Standard C library header <float.h>. SEE ALSO: ISO C subclause 7.1.5, 5.2.4.2.2, 5.2.4.2.1.
1 Header <cstdlib> (partial), Table 18:
Table 18---Header <cstdlib> synopsis |
_____________________________________________ Type Name(s) _____________________________________________ Macros: EXIT_FAILURE EXIT_SUCCESS _____________________________________________ Functions: abort atexit exit _____________________________________________ |
2 The contents are the same as the Standard C library header <stdlib.h>, with the following changes:
abort(void)
3 The function abort() has additional behavior in this International Standard:
extern "C" int atexit(void (*f)(void)) extern "C++" int atexit(void (*f)(void))
4 Effects: The atexit() functions register the function pointed to by f, to be called without arguments at normal program termination.
5 For the execution of a function registered with atexit(), if control leaves the function because it provides no handler for a thrown exception, terminate() is called (18.6.3.3).
6 Implementation Limits: The implementation shall support the registration of at least 32 functions.
7 Returns: The atexit() function returns zero if the registration succeeds, nozero if it fails.
exit(int status)
8 The function exit() has additional behavior in this International Standard:
9 The function exit() never returns to its caller. SEE ALSO: subclauses 3.6, 3.6.3, ISO C subclause 7.10.4.
207) Objects with automatic storage duration are all destroyed in a program whose function main() contains no automatic objects and executes the call to exit(). Control can be transferred directly to such a main() by throwing an exception that is caught in main(). [back to text]208) A function is called for every time it is registered. [back to text]
209) Any C streams associated with cin, cout, etc (27.3) are flushed and closed when static objects are destroyed in the previous phase. The function tmpfile() is declared in <cstdio>. [back to text]
210) The macros EXIT_FAILURE and EXIT_SUCCESS are defined in <cstdlib>. [back to text]
1 The header <new> defines several functions that manage the allocation of dynamic storage in a program. It also defines components for reporting storage management errors. Header <new> synopsis
SEE ALSO: 1.7, 3.7.3, 5.3.4, 5.3.5, 12.5, 20.4.namespace std { class bad_alloc; struct nothrow_t {}; extern const nothrow_t nothrow; typedef void (*new_handler)(); new_handler set_new_handler(new_handler new_p) throw(); } void* operator new(std::size_t size) throw(std::bad_alloc); void* operator new(std::size_t size, const std::nothrow_t&) throw(); void operator delete(void* ptr) throw(); void operator delete(void* ptr, const std::nothrow_t&) throw(); void* operator new[](std::size_t size) throw(std::bad_alloc); void* operator new[](std::size_t size, const std::nothrow_t&) throw(); void operator delete[](void* ptr) throw(); void operator delete[](void* ptr, const std::nothrow_t&) throw(); void* operator new (std::size_t size, void* ptr) throw(); void* operator new[](std::size_t size, void* ptr) throw(); void operator delete (void* ptr, void*) throw(); void operator delete[](void* ptr, void*) throw();
void* operator new(std::size_t size) throw(std::bad_alloc);
1 Effects: The allocation function (3.7.3.1) called by a new-expression (5.3.4) to allocate size bytes of storage suitably aligned to represent any object of that size.
2 Replaceable: a C++ program may define a function with this function signature that displaces the default version defined by the C++ Standard library.
3 Required behavior: Return a non-null pointer to suitably aligned storage (3.7.3), or else throw a
bad_alloc exception. This requirement is binding on a replacement version of this function.
4 Default behavior:
void* operator new(std::size_t size, const std::nothrow_t&) throw();
5 Effects: Same as above, except that it is called by a placement version of a new-expression when a C++ program prefers a null pointer result as an error indication, instead of a bad_alloc exception.
6 Replaceable: a C++ program may define a function with this function signature that displaces the default version defined by the C++ Standard library.
7 Required behavior: Return a non-null pointer to suitably aligned storage (3.7.3), or else return a null pointer. This nothrow version of operator new returns a pointer obtained as if acquired from the ordinary version. This requirement is binding on a replacement version of this function.
8 Default behavior:
9 [Example:
---end example]T* p1 = new T; // throws bad_alloc if it fails T* p2 = new(nothrow) T; // returns 0 if it fails
void operator delete(void* ptr) throw(); void operator delete(void* ptr, const std::nothrow_t&) throw();
10 Effects: The deallocation function (3.7.3.2) called by a delete-expression to render the value of ptr invalid.
11 Replaceable: a C++ program may define a function with this function signature that displaces the default version defined by the C++ Standard library.
12 Required behavior: accept a value of ptr that is null or that was returned by an earlier call to the default
operator new(std::size_t) or operator new(std::size_t,const std::nothrow_t&).
13 Default behavior:
14 Notes: It is unspecified under what conditions part or all of such reclaimed storage is allocated by a subsequent call to operator new or any of calloc, malloc, or realloc, declared in <cstdlib>.
void* operator new[](std::size_t size) throw(std::bad_alloc);
1 Effects: The allocation function (3.7.3.1) called by the array form of a new-expression (5.3.4) to allocate
size bytes of storage suitably aligned to represent any array object of that size or smaller.211)
2 Replaceable: a C++ program can define a function with this function signature that displaces the default version defined by the C++ Standard library.
3 Required behavior: Same as for operator new(std::size_t). This requirement is binding on a replacement version of this function.
4 Default behavior: Returns operator new(size). void* operator new[](std::size_t size, const std::nothrow_t&) throw();
5 Effects: Same as above, except that it is called by a placement version of a new-expression when a C++ program prefers a null pointer result as an error indication, instead of a bad_alloc exception.
6 Replaceable: a C++ program can define a function with this function signature that displaces the default version defined by the C++ Standard library.
7 Required behavior: Same as for operator new(std::size_t,const std::nothrow_t&). This nothrow version of operator new[] returns a pointer obtained as if acquired from the ordinary version.
8 Default behavior: Returns operator new(size,nothrow). void operator delete[](void* ptr) throw(); void operator delete[](void* ptr, const std::nothrow_t&) throw();
9 Effects: The deallocation function (3.7.3.2) called by the array form of a delete-expression to render the value of ptr invalid.
10 Replaceable: a C++ program can define a function with this function signature that displaces the default version defined by the C++ Standard library.
11 Required behavior: accept a value of ptr that is null or that was returned by an earlier call to operator new[](std::size_t) or operator new[](std::size_t,const std::nothrow_t&).
12 Default behavior:
13 It is unspecified under what conditions part or all of such reclaimed storage is allocated by a subsequent call to operator new or any of calloc, malloc, or realloc, declared in <cstdlib>.
211) It is not the direct responsibility of operator new[](std::size_t) or operator delete[](void*) to note the repetition count or element size of the array. Those operations are performed elsewhere in the array new and delete expressions. The array new expression, may, however, increase the size argument to operator new[](std::size_t) to obtain space to store supplemental information. [back to text]212) The value must not have been invalidated by an intervening call to operator delete[](void*) (17.4.3.7). [back to text]
1 These functions are reserved, a C++ program may not define functions that displace the versions in the Standard C++ library (17.4.3).
void* operator new(std::size_t size, void* ptr) throw();
2 Returns: ptr.
3 Notes: Intentionally performs no other action.
4 [Example: This can be useful for constructing an object at a known address:
---end example]char place[sizeof(Something)]; Something* p = new (place) Something();
void* operator new[](std::size_t size, void* ptr) throw();
5 Returns: ptr.
6 Notes: Intentionally performs no other action.
void operator delete(void* ptr, void*) throw();
7 Effects: Intentionally performs no action.
8 Notes: Default function called when any part of the initialization in a placement new expression that invokes the library's non-array placement operator new terminates by throwing an exception (5.3.4).
void operator delete[](void* ptr, void*) throw();
9 Effects: Intentionally performs no action.
10 Notes: Default function called when any part of the initialization in a placement new expression that invokes the library's array placement operator new terminates by throwing an exception (5.3.4).
namespace std { class bad_alloc : public exception { public: bad_alloc() throw(); bad_alloc(const bad_alloc&) throw(); bad_alloc& operator=(const bad_alloc&) throw(); virtual ~bad_alloc() throw(); virtual const char* what() const throw(); }; }
1 The class bad_alloc defines the type of objects thrown as exceptions by the implementation to report a failure to allocate storage.
bad_alloc() throw();
2 Effects: Constructs an object of class bad_alloc.
3 Notes: The result of calling what() on the newly constructed object is implementation-defined.
bad_alloc(const bad_alloc&) throw(); bad_alloc& operator=(const bad_alloc&) throw();
4 Effects: Copies an object of class bad_alloc.
virtual const char* what() const throw();
5 Returns: An implementation-defined NTBS.
typedef void (*new_handler)();
1 The type of a handler function to be called by operator new() or operator new[]() (18.4.1) when they cannot satisfy a request for additional storage.
2 Required behavior: A new_handler shall perform one of the following:
new_handler set_new_handler(new_handler new_p) throw();
1 Effects: Establishes the function designated by new_p as the current new_handler.
2 Returns: 0 on the first call, the previous new_handler on subsequent calls.
1 The header <typeinfo> defines a type associated with type information generated by the implementation. It also defines two types for reporting dynamic type identification errors. Header <typeinfo> synopsis
SEE ALSO: 5.2.7, 5.2.8.namespace std { class type_info; class bad_cast; class bad_typeid; }
namespace std { class type_info { public: virtual ~type_info(); bool operator==(const type_info& rhs) const; bool operator!=(const type_info& rhs) const; bool before(const type_info& rhs) const; const char* name() const; private: type_info(const type_info& rhs); type_info& operator=(const type_info& rhs); }; }
1 The class type_info describes type information generated by the implementation. Objects of this class effectively store a pointer to a name for the type, and an encoded value suitable for comparing two types for equality or collating order. The names, encoding rule, and collating sequence for types are all unspecified and may differ between programs.
bool operator==(const type_info& rhs) const;
2 Effects: Compares the current object with rhs.
3 Returns: true if the two values describe the same type.
bool operator!=(const type_info& rhs) const;
4 Returns: !(*this == rhs).
bool before(const type_info& rhs) const;
5 Effects: Compares the current object with rhs.
6 Returns: true if *this precedes rhs in the implementation's collation order.
const char* name() const;
7 Returns: an implementation-defined NTBS.
8 Notes: The message may be a null-terminated multibyte string (17.3.2.1.3.2), suitable for conversion and display as a wstring (21.2, 22.2.1.5) type_info(const type_info& rhs); type_info& operator=(const type_info& rhs);
9 Effects: Copies a type_info object.
10 Notes: Since the copy constructor and assignment operator for type_info are private to the class, objects of this type cannot be copied.
}class bad_cast : public exception { public: bad_cast() throw(); bad_cast(const bad_cast&) throw(); bad_cast& operator=(const bad_cast&) throw(); virtual ~bad_cast() throw(); virtual const char* what() const throw(); };
1 The class bad_cast defines the type of objects thrown as exceptions by the implementation to report the execution of an invalid dynamic-cast expression (5.2.7).
bad_cast() throw();
2 Effects: Constructs an object of class bad_cast.
3 Notes: The result of calling what() on the newly constructed object is implementation-defined.
bad_cast(const bad_cast&) throw(); bad_cast& operator=(const bad_cast&) throw();
4 Effects: Copies an object of class bad_cast.
virtual const char* what() const throw();
5 Returns: An implementation-defined NTBS.
6 Notes: The message may be a null-terminated multibyte string (17.3.2.1.3.2), suitable for conversion and display as a wstring (21.2, 22.2.1.5)
namespace std { class bad_typeid : public exception { public: bad_typeid() throw(); bad_typeid(const bad_typeid&) throw(); bad_typeid& operator=(const bad_typeid&) throw(); virtual ~bad_typeid() throw(); virtual const char* what() const throw(); }; }
1 The class bad_typeid defines the type of objects thrown as exceptions by the implementation to report a null pointer in a typeid expression (5.2.8).
bad_typeid() throw();
2 Effects: Constructs an object of class bad_typeid.
3 Notes: The result of calling what() on the newly constructed object is implementation-defined.
bad_typeid(const bad_typeid&) throw(); bad_typeid& operator=(const bad_typeid&) throw();
4 Effects: Copies an object of class bad_typeid.
virtual const char* what() const throw();
5 Returns: An implementation-defined NTBS.
6 Notes: The message may be a null-terminated multibyte string (17.3.2.1.3.2), suitable for conversion and display as a wstring (21.2, 22.2.1.5)
1 The header <exception> defines several types and functions related to the handling of exceptions in a C++ program. Header <exception> synopsis
SEE ALSO: 15.5.namespace std { class exception; class bad_exception; typedef void (*unexpected_handler)(); unexpected_handler set_unexpected(unexpected_handler f) throw(); void unexpected(); typedef void (*terminate_handler)(); terminate_handler set_terminate(terminate_handler f) throw(); void terminate(); bool uncaught_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(); }; }
1 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();
2 Effects: Constructs an object of class exception.
3 Notes: Does not throw any exceptions.
exception(const exception&) throw(); exception& operator=(const exception&) throw();
4 Effects: Copies an exception object.
5 Notes: The effects of calling what() after assignment are implementation-defined.
virtual ~exception() throw();
6 Effects: Destroys an object of class exception.
7 Notes: Does not throw any exceptions.
virtual const char* what() const throw();
8 Returns: An implementation-defined NTBS.
9 Notes: The message may be a null-terminated multibyte string (17.3.2.1.3.2), suitable for conversion and display as a wstring (21.2, 22.2.1.5)
}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(); };
1 The class bad_exception defines the type of objects thrown as described in (15.5.2). bad_exception() throw();
2 Effects: Constructs an object of class bad_exception.
3 Notes: The result of calling what() on the newly constructed object is implementation-defined.
bad_exception(const bad_exception&) throw(); bad_exception& operator=(const bad_exception&) throw();
4 Effects: Copies an object of class bad_exception. virtual const char* what() const throw();
5 Returns: An implementation-defined NTBS.
6 Notes: The message may be a null-terminated multibyte string (17.3.2.1.3.2), suitable for conversion and display as a wstring (21.2, 22.2.1.5)
typedef void (*unexpected_handler)();
1 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.
2 Required behavior: An unexpected_handler shall not return. See also 15.5.2.
3 Default behavior: The implementation's default unexpected_handler calls terminate().
unexpected_handler set_unexpected(unexpected_handler f) throw();
1 Effects: Establishes the function designated by f as the current unexpected_handler.
2 Requires: f shall not be a null pointer.
3 Returns: The previous unexpected_handler.
void unexpected();
1 Called by the implementation when a function exits via an exception not allowed by its exception-specification (15.5.2). May also be called directly by the program.
2 Effects: Calls the unexpected_handler function in effect immediately after evaluating the throw-expression (18.6.2.2), if called by the implementation, or calls the current unexpected_handler, if called by the program.
typedef void (*terminate_handler)();
1 The type of a handler function to be called by terminate() when terminating exception processing.
2 Required behavior: A terminate_handler shall terminate execution of the program without returning to the caller.
3 Default behavior: The implementation's default terminate_handler calls abort().
terminate_handler set_terminate(terminate_handler f) throw();
1 Effects: Establishes the function designated by f as the current handler function for terminating exception processing.
2 Requires: f shall not be a null pointer.
3 Returns: The previous terminate_handler.
void terminate();
1 Called by the implementation when exception handling must be abandoned for any of several reasons (15.5.1). May also be called directly by the program.
2 Effects: Calls the terminate_handler function in effect immediately after evaluating the throw-expression (18.6.3.1), if called by the implementation, or calls the current terminate_handler function, if called by the program.
bool uncaught_exception();
1 Returns: true after completing evaluation of a throw-expression until either completing initialization of the exception-declaration in the matching handler or entering unexpected() due to the throw; or after entering terminate() for any reason other than an explicit call to terminate(). [Note: This includes stack unwinding (15.2). ---end note]
2 Notes: When uncaught_exception() is true, throwing an exception can result in a call of terminate() (15.5.1).
1 Headers <cstdarg> (variable arguments), <csetjmp> (nonlocal jumps), <ctime> (system clock clock(), time()), <csignal> (signal handling), and <cstdlib> (runtime environment getenv(), system()).
Table 19---Header <cstdarg> synopsis | ||||||||
_ ________________________________________ _ Type Name(s) ________________________________________ _ Macros: va_arg va_end va_start ________________________________________ _ Type: va_list ________________________________________ |
2 The contents of these headers are the same as the Standard C library headers <stdarg.h>, <setjmp.h>, <time.h>, <signal.h>, and <stdlib.h> respectively, with the following changes:
3 The restrictions that ISO C places on the second parameter to the va_start() macro in header <stdarg.h> are different in this International Standard. The parameter parmN is the identifier of the rightmost parameter in the variable parameter list of the function definition (the one just before the ...). If the parameter parmN is declared with a function, array, or reference type, or with a type that is not compatible with the type that results when passing an argument for which there is no parameter, the behavior is undefined. SEE ALSO: ISO C subclause 4.8.1.1.
4 The function signature longjmp(jmp_buf jbuf, int val) has more restricted behavior in this International Standard. If any automatic objects would be destroyed by a thrown exception transferring control to another (destination) point in the program, then a call to longjmp(jbuf, val) at the throw point that transfers control to the same (destination) point has undefined behavior. SEE ALSO: ISO C subclause 7.10.4, 7.8, 7.6, 7.12.
5 The common subset of the C and C++ languages consists of all declarations, definitions, and expressions that may appear in a well formed C++ program and also in a conforming C program. A POF (``plain old function'') is a function that uses only features from this common subset, and that does not directly or indirectly use any function that is not a POF. All signal handlers shall have C linkage. A POF that could be used as a signal handler in a conforming C program does not produce undefined behavior when used as a signal handler in a C++ program. The behavior of any other function used as a signal handler in a C++ program is implementation defined.213)
213) In particular, a signal handler using exception handling is very likely to have problems [back to text]