bad_alloc

#include <iostream> #include <exception> using namespace std; int main () throw ( exception ) { const unsigned long SIZE = 500000000; char *ptr[10]; try { for ( int counter = 0; counter < 10; counter++ ) { ptr[counter] = new char[SIZE]; cout << "Memory for ptr[" << counter << "] is allocated" << endl; } } catch (exception &e) // catch ( ... ) { cout << "Exception: "; cout << e.what() << endl; return 1; } for ( int i = 0; i < 10; i++ ) delete [] ptr[i]; cout << "End" << endl; return 0; } OUTPUT: // Memory for ptr[0] is allocated // Memory for ptr[1] is allocated // Memory for ptr[2] is allocated // Memory for ptr[3] is allocated // Memory for ptr[4] is allocated // Exception: bad_alloc