// exception2.cpp By: Aiman Hanna - ©1993-2006 Aiman Hanna // Again, exceptions are run-time program anomalies. Programmers // generally develop their own style for handling exceptions. // This program shows some example of these styles to handle a situation // where the new operator (request for dynamic memory allocations fails. // Key Points: 1) "non-standard" ways for handling exceptions #include "exception2.h" int NSHandle1( ) { int *ptr1 = new int[999999999]; if (ptr1 == 0) // same as if (ptr == NULL) { cerr << "Could not allocate needed memory" << endl; cout << "Function will return immediately" << endl; return (-1); } cout << "Allocation is fine. " << endl; delete [] ptr1; return 0; } int NSHandle2( ) { // This is the worst and most common. Just trust that it won't happen char *ptr1 = new char[30]; // just use the assumed allocated space strcpy(ptr1, "I am always lucky"); cout <