bad_alloc.cc
changeset 29 7abf6146898e
parent 28 54addf5893ef
child 77 49e0babccb23
equal deleted inserted replaced
28:54addf5893ef 29:7abf6146898e
    25 }
    25 }
    26 
    26 
    27 int main (int argc, char **argv)
    27 int main (int argc, char **argv)
    28 {
    28 {
    29     vector < int >v;
    29     vector < int >v;
       
    30 
    30     int i = 0;
    31     int i = 0;
       
    32 
    31     char action;
    33     char action;
    32 
    34 
    33     if (set_limit (20 * 1024 * 1024)) {
    35     if (set_limit (20 * 1024 * 1024)) {
    34         cout << "System error" << endl;
    36         cout << "System error" << endl;
    35         return EXIT_FAILURE;
    37         return EXIT_FAILURE;
    37 
    39 
    38     try {
    40     try {
    39         for (;;) {
    41         for (;;) {
    40             v.push_back (i++);
    42             v.push_back (i++);
    41         }
    43         }
    42     } catch (exception & e) {
    44     }
       
    45     catch (exception & e) {
    43         cout << e.what () << " after " << i << " iterations" << endl << endl;
    46         cout << e.what () << " after " << i << " iterations" << endl << endl;
    44         cout << "Would you like to see the full error message? (y/n) ";
    47         cout << "Would you like to see the full error message? (y/n) ";
    45         cin >> action;
    48         cin >> action;
    46         v.clear();
    49         v.clear ();
    47         switch (action) {
    50         switch (action) {
    48         case 'y':
    51         case 'y':
    49             throw;
    52             throw;
    50             break;
    53             break;
    51         }
    54         }