The new-handler function is the function called by allocation functions
whenever a memory allocation attempt fails. Its intended purpose is one of
three things:
make more memory available. ( resolve myself)
throw exception of type std::bad_alloc or derived from
std::bad_alloc. (resolve by user)
terminate the program. e.g. by calling std::terminate. (Noresolve)
At program startup, new-handler is a null pointer. allocation function finds
that std::get_new_handler returns a null pointer value, it will throw
std::bad_alloc.
The default implementation throws std::bad_alloc. The user can install his
own new-handler, which may offer behavior different than the default
one.
If new-handler returns, the allocation function repeats the previously-failed
allocation attempt and calls the new-handler again if the allocation fails again.
To end the loop, new-handler may call std::set_new_handler(nullptr).
Use set_new_handler function. When memory allocate failed, it will call
this "callback" function.