Files
2025-10-25 03:02:53 +03:00

131 lines
4.5 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[alloc.errors]
# 17 Language support library [[support]](./#support)
## 17.6 Dynamic memory management [[support.dynamic]](support.dynamic#alloc.errors)
### 17.6.4 Storage allocation errors [alloc.errors]
#### [17.6.4.1](#bad.alloc) Class bad_alloc [[bad.alloc]](bad.alloc)
[🔗](#lib:bad_alloc,constructor)
namespace std {class bad_alloc : public exception {public:// see [[exception]](exception "17.9.3Class exception") for the specification of the special member functionsconstexpr const char* what() const noexcept override; };}
[1](#bad.alloc-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3031)
The classbad_alloc defines the type of objects thrown as
exceptions by the implementation to report a failure to allocate storage[.](#bad.alloc-1.sentence-1)
[🔗](#lib:what,bad_alloc)
`constexpr const char* what() const noexcept override;
`
[2](#bad.alloc-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3043)
*Returns*: An implementation-defined ntbs[.](#bad.alloc-2.sentence-1)
#### [17.6.4.2](#new.badlength) Class bad_array_new_length [[new.badlength]](new.badlength)
namespace std {class bad_array_new_length : public bad_alloc {public:// see [[exception]](exception "17.9.3Class exception") for the specification of the special member functionsconstexpr const char* what() const noexcept override; };}
[1](#new.badlength-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3062)
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]](expr.new "7.6.2.8New"))[.](#new.badlength-1.sentence-1)
[🔗](#lib:what,bad_array_new_length)
`constexpr const char* what() const noexcept override;
`
[2](#new.badlength-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3074)
*Returns*: An implementation-defined ntbs[.](#new.badlength-2.sentence-1)
#### [17.6.4.3](#new.handler) Type new_handler [[new.handler]](new.handler)
[🔗](#lib:new_handler)
`using new_handler = void (*)();
`
[1](#new.handler-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3087)
The type of a[*handler function*](#def:handler_function) to be called byoperator new() oroperator new[]() ([[new.delete]](new.delete "17.6.3Storage allocation and deallocation")) when they cannot satisfy a request for additional storage[.](#new.handler-1.sentence-1)
[2](#new.handler-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3095)
*Required behavior*: A new_handler shall perform one of the following:
- [(2.1)](#new.handler-2.1)
make more storage available for allocation and then return;
- [(2.2)](#new.handler-2.2)
throw an exception of typebad_alloc or a class derived frombad_alloc;
- [(2.3)](#new.handler-2.3)
terminate execution of the program without returning to the caller[.](#new.handler-2.sentence-1)
#### [17.6.4.4](#set.new.handler) set_new_handler [[set.new.handler]](set.new.handler)
[🔗](#lib:set_new_handler)
`new_handler set_new_handler(new_handler new_p) noexcept;
`
[1](#set.new.handler-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3122)
*Effects*: Establishes the function designated by new_p as the currentnew_handler[.](#set.new.handler-1.sentence-1)
[2](#set.new.handler-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3127)
*Returns*: The previous new_handler[.](#set.new.handler-2.sentence-1)
[3](#set.new.handler-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3131)
*Remarks*: The initial new_handler is a null pointer[.](#set.new.handler-3.sentence-1)
#### [17.6.4.5](#get.new.handler) get_new_handler [[get.new.handler]](get.new.handler)
[🔗](#lib:get_new_handler)
`new_handler get_new_handler() noexcept;
`
[1](#get.new.handler-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3144)
*Returns*: The current new_handler[.](#get.new.handler-1.sentence-1)
[*Note [1](#get.new.handler-note-1)*:
This can be a null pointer value[.](#get.new.handler-1.sentence-2)
— *end note*]