Member Data on the Heap

Hello!

Now straight to business. I was wondering, if you had class member data on the heap, like for example
 
 int *pfoo = new int;

how would you handle it being null?
you're checking for a null pointer in the constructor,
1
2
3
4
if (pfoo == NULL) {
delete pfoo;
pfoo = 0;
}

and if it is null, would the program stop automatically, and halt constructing the object, or is there a way to deal with this if it happens?
If new int fails it will throw an exception of type std::bad_alloc. If this happens inside the constructor and the exception is not caught this will prevent the object from being created.
thanks!
Topic archived. No new replies allowed.