// INSERT1.CPP - First example from Section 8.3.1 // Adapted by Agustin Gonzalez // We added a catch clause in main() to show the results // of throwing the exception a second time. #include #include "range.h" const unsigned ArraySize = 50; int array[ArraySize]; void InsertValue( unsigned i, int value ) { if( i >= ArraySize ) throw RangeError(__FILE__, __LINE__, i); // __FILE__ is a macro that returns the current // file name.__LINE__ is a macro that returns de line number array[i] = value; } void TestTheArray() { unsigned j; int anInt; cout << "Enter a subscript (0-49) and a value: "; cin >> j >> anInt; try { InsertValue( j, anInt ); } catch( const RangeError & R) { cout << "Range error in TestTheArray()\n"; cout << R; throw R; } } int main() { try { TestTheArray(); } catch( const RangeError & ) { cout << "Range error in main()\n"; } return 0; }