32 lines
492 B
C++
32 lines
492 B
C++
#include <malloc.h>
|
|
#include <iostream>
|
|
#include <exception>
|
|
|
|
|
|
void * operator new ( size_t s, const std::string& str )
|
|
{
|
|
std::cout << str << std::endl;
|
|
return malloc( s );
|
|
}
|
|
|
|
|
|
int main ( void )
|
|
{try{
|
|
|
|
int * i = new (std::string("Hello")) int;
|
|
return 0;
|
|
}
|
|
catch ( const std::exception& e )
|
|
{
|
|
std::cerr << std::endl
|
|
<< "std::exception(\"" << e.what() << "\")." << std::endl;
|
|
return 2;
|
|
}
|
|
catch ( ... )
|
|
{
|
|
std::cerr << std::endl
|
|
<< "unknown exception." << std::endl;
|
|
return 1;
|
|
}}
|
|
|