#include #include #include #include using namespace std; int main() { vectordata{1,3,5,7,9}; cout << "Catching with exception" << endl; try { cout << "\tThrowing a logic_error" << endl; throw logic_error("can't touch this") ; } catch (const exception & e) { cout << "\t\tCaught " << e.what() << endl; } cout << endl << endl; cout << "Catching an exception, but note the message changes" << endl; cout << endl; try { cout << "\tData.at(data.size()) is "; cout << data.at(data.size()) << endl; } catch (const logic_error & e) { cout << " Caught " << e.what() << endl; } catch (...) { cout << " In the generic excption handler" << endl; } cout << endl << endl; cout << "Catching with a logic_error" << endl; for(int i =0; i < 2; i++) { try { switch(i) { case 1: cout << "\tThrowing an exception" << endl; throw exception(); case 0: cout << "\tThrowing a logic_error " << endl; throw logic_error("Custom message"); } } catch (const logic_error & e) { cout << "\t\tCaught " << e.what() << endl; } cout << endl << endl; } return 0; }