// File: tdtest12.cpp // // This file checks that version 11 of // the TwoDimArray class works. // // Version 11 throws exceptions // #include #include "twodim12.h" using namespace std ; void foo() { TwoDimArray A(5,5) ; try { // open some files A[19][24] = 72 ; // do some other stuff } catch (OutOfBounds& e) { cerr << "Oops! Out of Bounds detected!\n" ; cerr << e.what() << ": " << e.bad_index << " >= " << e.max_index << "\n" ; // preparation for ending foo(), close files // rethrow exception throw ; } } int main() { try { // other code foo() ; // other code } catch (OutOfBounds& e) { cerr << "Caught in main program!\n" ; // preparation for exit (e.g., close files) exit(1) ; } }