#include #include using namespace std; extern int someFunction() noexcept; // this annotation is UNCHECKED by the compiler! class Fin { public: Fin(int n) { name = n; cout << "Fin constructor(" << name << ")" << endl; } ~Fin() { cout << "Fin destructor(" << name << ")" << endl; } private: int name; }; string helloWorld() { return "Hello world!"; } void handler() { cout << "In handler" << endl; throw; // this is called a "rethrow" } int main(int argc, char* argv[]) { int x = 10; int &ref = x; int const & constRef = x; const int constInt = 20; int *pX = &x; double y = 100.0; string str = "a string"; float floatVar = 1000.0; while ( cin.good() ) { int which; cin >> which; if ( !cin.good() ) throw "cin input failed"; try { Fin localFin(which); switch(which) { case 0: throw x; case 1: throw y; case 2: throw str; case 3: throw floatVar; case 4: throw pX; case 5: throw ref; case 6: throw constInt; case 7: throw constRef; case 8: throw helloWorld; } } catch (int &intRefException ) { cout << "int & exception: " << intRefException << endl; } catch (int intException) { cout << "Int exception: " << intException << endl; } catch (int *ptrException ) { cout << "int * exception: " << *ptrException << endl; } catch ( const int constIntException) { cout << "Const int exception: " << constIntException << endl; } catch (double doubleException ) { cout << "Double exception: " << doubleException << endl; } catch (string strException ) { cout << "String exception: " << strException << endl; } catch ( string (*func)() ) { cout << "Function exception: " << func() << endl; } catch (...) { handler(); } } // end of while loop return EXIT_SUCCESS; }