Will new operator return NULL? [duplicate]
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Will new return NULL in any case? Say i have a class Car and i create an object Car *newcar = new Car(); if(newcar==NULL) //is it valid to check for NULL if new runs out of memory { } 回答1: On a standards-conforming C++ implementation, no. The ordinary form of new will never return NULL ; if allocation fails, a std::bad_alloc exception will be thrown (the new (nothrow) form does not throw exceptions, and will