[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/memory/new/nothrow [Back]  [Original]

std::nothrow cppreference.com
cppreference.com

std::nothrow

cppreference.com
< cpp | memory | new
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
 
no section name
no section name
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)



no section name
 
 
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>
struct nothrow_t {};
( C++11)
struct nothrow_t { explicit nothrow_t() = default; };
( C++11)
extern const std::nothrow_t nothrow;

std::nothrow_t , . std::nothrow .

#include <iostream>
#include <new>

int main()
{
    try
    {
        while (true)
        {
            new int[100000000ul];   //   
        }
    }
    catch (const std::bad_alloc& e)
    {
        std::cout << e.what() << '\n';
    }

    while (true)
    {
        //    
        int* p = new(std::nothrow) int[100000000ul];
        if (p == nullptr)
        {
            std::cout << "  nullptr\n";
            break;
        }
    }
}

:

std::bad_alloc
  nullptr

C++:

LWG 2510 C++11 ,


() []

Web Proxy Viewer  |  New URL  |  Original Page