std::nothrow
cppreference.com
<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 | , |
| () |