/****************************************************************************** *** FILE: exception.cpp *** DATE: 03/17/2004 *** AUTHOR: Daniel Dementiev *** GOAL: This program illustrates how to use exception handling technique. *** Please pay attention to the usage of the keywords: *** - throw *** - try *** - catch ******************************************************************************/ #include #include using namespace std; class Array { private: int count; int data[10]; int size; public: Array() : count(0), size(10) {}; int Count() const { return count; }; int Size() const { return size; }; int& Item(int index); }; int& Array::Item(int index) { if( index<0 || index>=10 ) throw out_of_range("index is out of range in the method Array::Item(int index)"); return data[index]; } void main() { Array a; try{ cout<<"count = "<