// try_try2.cc demonstrate how the type of 'catch' get various 'throw' #include using namespace std; int main() { typedef int my_int; my_int k; for(int i=0; i<5; i++) { cout << i << '\n'; try { cout << "in try block, i= " << i << '\n'; if(i==0) throw "first exception"; cout << "in try block after first if \n"; if(i==1) throw i; cout << "in try block after second if \n"; if(i==2) throw (float)i; cout << "in try block after third if \n"; if(i==3) { k=i; throw k;} cout << "in try block after third if \n"; throw 12.5; // a double cout << "should not get here \n"; // compiler warning also } catch(const char * my_string){ cout << "my_string " << my_string << '\n'; } catch(const int j){ cout << "caught an integer = " << j << '\n'; } catch(const double j){ cout << "caught a double = " << j << '\n'; } catch(...){ cout << "caught something \n" << '\n' << '\n'; } cout << "outside the try block \n"; } cout << "outside the loop, normal return \n"; return 0; } // end main