// test of operator new exceptions #include "xgmem.h" #include <iostream> using std::cout; using std::endl; int main() { enum { SMALL_MAX = 200, BIG_MAX = 500000000 }; try { int *p1 = new int[SMALL_MAX]; // normal allocation int *p2 = new int[BIG_MAX]; // exception allocation // user-defined new //..use p delete p1; // user-defined delete delete p2; // user-defined delete } catch (std::bad_alloc & x) { std::cout << x.what() << endl; // display exception } }
Hosted by www.Geocities.ws

1