#include #include #include #include using namespace std; class SillyT { public: SillyT(string n) : name {n} { cout << "\tBuilding " << name << endl; }; ~SillyT() { cout << "\tDestroying " << name << endl; } string Name() { return name; } private: string name; }; void PrintValue(vector & a, size_t i) { SillyT st("In Function"); cout << "Entering function" << endl; cout << i << " " << a.at(i) << " for " << st.Name() << endl; cout << "Exiting function" << endl; } void Thrower2() { throw (exception{}); } void Thrower() { cout << "In Thrower " << endl; throw (5); cout << "Exiting Thrower " << endl; } int main() { vector a{1,2,3}; size_t i; for(i = 0; i <= a.size(); ++i) { try { SillyT st1{"From the try block"}; cout << "Entering the block " << endl; PrintValue(a, i); cout << "I got here" << endl; } catch (...) { cout << "Caught an error " << endl; } cout << endl; } cout << endl << endl << endl; cout << "After the loop" << endl; cout << "Calling Thrower " << endl; try { Thrower() ; } catch (string s) { cout << "Caught the string " << s << endl; } catch (short k) { cout << "Caught the short " << k << endl; } catch (int j) { cout << "Caught the int " << j << endl; } catch (...) { cout << "Caught the default case " << endl; } cout << "After Thrower" << endl; cout << endl << endl ; try { Thrower2(); } catch (const exception & e) { cout << "Caught an exception " << e.what() << endl; } return 0; }