Files
cppdraft_translate/cppdraft/alloc/errors.md
2025-10-25 03:02:53 +03:00

4.5 KiB

[alloc.errors]

17 Language support library [support]

17.6 Dynamic memory management [support.dynamic]

17.6.4 Storage allocation errors [alloc.errors]

17.6.4.1 Class bad_alloc [bad.alloc]

🔗

namespace std {class bad_alloc : public exception {public:// see [exception] for the specification of the special member functionsconstexpr const char* what() const noexcept override; };}

1

#

The classbad_alloc defines the type of objects thrown as exceptions by the implementation to report a failure to allocate storage.

🔗

constexpr const char* what() const noexcept override;

2

#

Returns: An implementation-defined ntbs.

17.6.4.2 Class bad_array_new_length [new.badlength]

namespace std {class bad_array_new_length : public bad_alloc {public:// see [exception] for the specification of the special member functionsconstexpr const char* what() const noexcept override; };}

1

#

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]).

🔗

constexpr const char* what() const noexcept override;

2

#

Returns: An implementation-defined ntbs.

17.6.4.3 Type new_handler [new.handler]

🔗

using new_handler = void (*)();

1

#

The type of ahandler function to be called byoperator new() oroperator new ([new.delete]) when they cannot satisfy a request for additional storage.

2

#

Required behavior: A new_handler shall perform one of the following:

make more storage available for allocation and then return;

throw an exception of typebad_alloc or a class derived frombad_alloc;

terminate execution of the program without returning to the caller.

17.6.4.4 set_new_handler [set.new.handler]

🔗

new_handler set_new_handler(new_handler new_p) noexcept;

1

#

Effects: Establishes the function designated by new_p as the currentnew_handler.

2

#

Returns: The previous new_handler.

3

#

Remarks: The initial new_handler is a null pointer.

17.6.4.5 get_new_handler [get.new.handler]

🔗

new_handler get_new_handler() noexcept;

1

#

Returns: The current new_handler.

[Note 1:

This can be a null pointer value.

— end note]