// exception3.cpp // Diep Thi Hoang #include #include using namespace std; class EmptyArrayException123: public exception{ public: const char* what() const throw(){ return "Exception: Cannot find max of an empty array!"; } }; int getArrayMax(int a[], int n){ if(n == 0){ EmptyArrayException123 e; throw e; } int max = a[0]; for(int i = 1; i < n; i++) if(a[i] > max) max = a[i]; return max; } int main () { try { int b[3] = {6, 9, 2}; cout << "max in b = " << getArrayMax(b, 0) << endl; } catch(exception& e) { cout << e.what(); } cin.ignore(); cin.get(); return 0; }