Object pointer state after a new constructor throws an exception - C ++

What will be the status of an object pointer when a new class constructor throws an exception in C ++? Take the following code, for example:

CMyClass * pobjMyClass = (CMyClass *)0xA5A5A5A5;

try
{
    pobjMyClass = new CMyClass(); // Exception thrown in constructor
}
catch ( ... ) {}

When does this code execute what will mean pobjMyClassafter the exception is thrown? A pointer to an invalid copy of CMyClass, 0xA5A5A5A5, NULL, some random uninitialized value, or something else? Thank.

+5
source share
1 answer

Since the exception is thrown before the destination, pobjMyClass will be what it used to be - in your case, 0xa5a5a5a5.

+6

All Articles