'Question about operator new overload and exception
Why this code snippet ouputs a lot of "here"?
I think the program should terminate when after throw std::invalid_argument( "fool" ); has been called.
#include <memory>
#include <iostream>
void* operator new(std::size_t size)
{
std::cout << "here" << std::endl;
throw std::invalid_argument( "fool" ); //commit out this, there would be many many ouputs
return std::malloc(size);
}
void operator delete(void* ptr)
{
return free(ptr);
}
int main()
{
//std::unique_ptr<int> point2int(new int(999));
int* rawpoint2int = new int(666);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
