// File: tdtest12.cpp // // This file checks that version 12 of // the TwoDimArray class works. // // Version 12 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 (const 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 (const OutOfBounds& e) { // try it without const cerr << "Caught in main program!\n" ; // preparation for exit (e.g., close files) exit(1) ; } }