#include #include #include using namespace std; int main() { vectordata{1,3,5,7,9}; // this is for demo purpose only. // // DO NOT THROW AN EXCEPTION DIRECTLY INSIDE OF THE TRY BLOCK // UNLESS IT IS TOTALLY UNRELATED TO THE THING YOU ARE TRYING // THIS IS BAD CODE // // This is for demo purposes only. cout << "Throwing and catching an exception " << endl; try { throw exception(); } 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 << "Data.at(data.size()) is " << endl; // throw range_error("This is a dumb thing"); cout << endl; cout << data.at(data.size()) << endl; cout << "And that is that " << endl; cout << endl; } catch (const logic_error & e) { cout << "\t\tCaught logic error " << e.what() << endl; } catch (const out_of_range & e) { cout << "\t\tCaught out of range " << e.what() << endl; } catch (const exception & e) { cout << "\t\tCaught EXCEPT " << e.what() << endl; } catch (...) { cout << "In the generic excption handler" << endl; } cout << endl << endl; return 0; }