new 失败处理方法

new 失败不产生崩溃的处理方法:

void *__cdecl operator new(size_t cb, const std::nothrow_t&) throw()
{
    char *p;
    try 
    {
        p = new char[cb];
    }
    catch (std::bad_alloc) 
    {
        p = 0;
    }
    return p;
}

你可能感兴趣的:(new 失败处理方法)