By default, new should throw a bad_alloc exception, so no checks are required.
VC6, on the other hand, returns 0 on bad_alloc, in which case Type 3 should be fine in cases where you don't have nullptr (which is in the C ++ 11 standard)
Another way to test for NULL is to call new with std :: nothrow:
ptr = new(std::nothrow) Test();
In any case, remember that you do not need to catch every bad_alloc where it was thrown. You better catch him where you can react to him (free memory or skillfully gracefully).
source share