New (C++) - Implementation

Implementation

In compilers conforming to the ISO C++ standard, if there is not enough memory for the allocation, a new_handler function will be called (if registered) until requested memory can be provided. If the new_handler fails to allocate enough memory or no new_handler is set, the code throws an exception of type std::bad_alloc. All subsequent code is aborted until the error is handled in a try-catch block or the program exits abnormally. The program does not need to check the value of the pointer; if no exception was thrown, the allocation succeeded. The implemented operations are defined in the header . In most C++ implementations the new operator can also be overloaded to define specific behaviors.

Read more about this topic:  New (C++)