#include #include #include //for classes bad_alloc and bad_array_new_length using namespace std; int main() { try { //Get a block of memeort big enough to hold an array of 100 ints. int *const p {new int[100]}; //or try it with 2147483647 p[0] = 1234; cout << "p[0] = " << p[0] << "\n"; delete[] p; } catch (const bad_array_new_length& ex) { cerr << "Bad (e.g., negative) number of elements in array " << ex.what() << "\n"; return EXIT_FAILURE; } catch (const bad_alloc& ex) { cerr << "Not enough memory " << ex.what() << "\n"; return EXIT_FAILURE; } catch (...) { //none of the above cout << "Unexpected type of exception thrown.\n"; return EXIT_FAILURE; } return EXIT_SUCCESS; }