#include <iostream>
#include <new>
int main()
{
try
{
while(true)
{
new int[100000000ul]; // throwing overload
}
}
catch (const std::bad_alloc& e)
{
std::cout << e.what() << std::endl;
}
while (true)
{
int* p = new(std::nothrow) int[100000000ul]; // non-throwing overload
if (p == nullptr)
{
std::cout << "Allocation returned nullptr" << std::endl;
break;
}
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bmV3PgogCmludCBtYWluKCkKewogICAgdHJ5CiAgICB7CiAgICAgICAgd2hpbGUodHJ1ZSkKICAgICAgICB7CiAgICAgICAgICAgIG5ldyBpbnRbMTAwMDAwMDAwdWxdOyAgIC8vIHRocm93aW5nIG92ZXJsb2FkCiAgICAgICAgfQogICAgfQogICAgY2F0Y2ggKGNvbnN0IHN0ZDo6YmFkX2FsbG9jJiBlKQogICAgewogICAgICAgIHN0ZDo6Y291dCA8PCBlLndoYXQoKSA8PCBzdGQ6OmVuZGw7CiAgICB9CiAKICAgIHdoaWxlICh0cnVlKQogICAgewogICAgICAgIGludCogcCA9IG5ldyhzdGQ6Om5vdGhyb3cpIGludFsxMDAwMDAwMDB1bF07IC8vIG5vbi10aHJvd2luZyBvdmVybG9hZAogICAgICAgIGlmIChwID09IG51bGxwdHIpCiAgICAgICAgewogICAgICAgICAgICBzdGQ6OmNvdXQgPDwgIkFsbG9jYXRpb24gcmV0dXJuZWQgbnVsbHB0ciIgIDw8IHN0ZDo6ZW5kbDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgfQp9