#include #include #include #include #include #include using namespace std; void exception1() { try { int* myarray= new int[1000000000000000]; } catch (exception& e) { cout << "Standard exception: " << e.what() << endl; } } void exception2() { ofstream file; file.exceptions(ofstream::failbit | ofstream::badbit); try { file.open("output.txt", ios_base::app); file << "Write this to the file" << endl; file.close(); } catch (ofstream::failure &e) { cout << "Exception writing to file: " << file.rdstate() << endl; } } void exception3helper(int x) throw(int, string) { if(x < 10) { throw 1; } else if (x > 100) { throw 2; } else if (x == 47) { string s("hidden message"); throw s; } else { cout << "Just right" << endl; } } void exception3() { try { exception3helper(47); } catch (int excNumber) { if(excNumber == 1) { cout << "Number too small exception thrown" << endl; } else if (excNumber == 2) { cout << "Number too big exception thrown" << endl; } else { cout << "Unknown integer exception" << endl; } } catch (string excString) { cout << "String exception: " << excString << endl; } } int main () { exception3(); cout << "return to main" << endl; return (0); }