#include #include #include using namespace std; inline void *operator new(size_t n) throw (bad_alloc) { cout << "operator new without nothrow\n"; if (void *const p = malloc(n)) { return p; } throw bad_alloc(); }; inline void operator delete(void *p) throw () { cout << "operator delete without nothrow\n"; free(p); } inline void *operator new(size_t n, const nothrow_t&) throw () { cout << "operator new with nothrow\n"; return malloc(n); } inline void operator delete(void *p, const nothrow_t&) throw () { cout << "operator delete with nothrow\n"; free(p); } class obj { public: obj() throw (int) {throw 10;} }; int main() { try { obj *const p1 = new obj; } catch (int i) { cout << "caught " << i << "\n"; } catch (...) { cout << "caught exception other than int\n"; } try { obj *const p2 = new(nothrow) obj; } catch (int i) { cout << "caught " << i << "\n"; } catch (...) { cout << "caught exception other than int\n"; } return EXIT_SUCCESS; }