21 Language support library [language.support]

21.6 Dynamic memory management [support.dynamic]

21.6.3 Storage allocation errors [alloc.errors]

21.6.3.1 Class bad_­alloc [bad.alloc]

namespace std {
  class bad_alloc : public exception {
  public:
    bad_alloc() noexcept;
    bad_alloc(const bad_alloc&) noexcept;
    bad_alloc& operator=(const bad_alloc&) noexcept;
    const char* what() const noexcept override;
  };
}
The class bad_­alloc defines the type of objects thrown as exceptions by the implementation to report a failure to allocate storage.
bad_alloc() noexcept;
Effects: Constructs an object of class bad_­alloc.
bad_alloc(const bad_alloc&) noexcept; bad_alloc& operator=(const bad_alloc&) noexcept;
Effects: Copies an object of class bad_­alloc.
const char* what() const noexcept override;
Returns: An implementation-defined ntbs.
Remarks: The message may be a null-terminated multibyte string ([multibyte.strings]), suitable for conversion and display as a wstring ([string.classes], [locale.codecvt]).

21.6.3.2 Class bad_­array_­new_­length [new.badlength]

namespace std {
  class bad_array_new_length : public bad_alloc {
  public:
    bad_array_new_length() noexcept;
    const char* what() const noexcept override;
  };
}
The class bad_­array_­new_­length defines the type of objects thrown as exceptions by the implementation to report an attempt to allocate an array of size less than zero or greater than an implementation-defined limit ([expr.new]).
bad_array_new_length() noexcept;
Effects: constructs an object of class bad_­array_­new_­length.
const char* what() const noexcept override;
Returns: An implementation-defined ntbs.
Remarks: The message may be a null-terminated multibyte string ([multibyte.strings]), suitable for conversion and display as a wstring ([string.classes], [locale.codecvt]).

21.6.3.3 Type new_­handler [new.handler]

using new_handler = void (*)();
The type of a handler function to be called by operator new() or operator new[]() ([new.delete]) when they cannot satisfy a request for additional storage.
Required behavior: A new_­handler shall perform one of the following:
  • make more storage available for allocation and then return;
  • throw an exception of type bad_­alloc or a class derived from bad_­alloc;
  • terminate execution of the program without returning to the caller.

21.6.3.4 set_­new_­handler [set.new.handler]

new_handler set_new_handler(new_handler new_p) noexcept;
Effects: Establishes the function designated by new_­p as the current new_­handler.
Returns: The previous new_­handler.
Remarks: The initial new_­handler is a null pointer.

21.6.3.5 get_­new_­handler [get.new.handler]

new_handler get_new_handler() noexcept;
Returns: The current new_­handler.
[Note
:
This may be a null pointer value.
end note
]