קשה לנחש מה עשית אבל
באופן כללי זה אמור להיראות כך:
// file: exception.cpp #include <iostream> #include <vector> #include <stdexcept> using namespace std; int main() { vector<int> v(20); // fill the vector // for (int i = 0; i < 20; i++) { v = i; } // display values with exception out_of_range // try{ for (int i = 0; i < 20; i++) { cout << v.at(i+1); } } catch(out_of_range e){ cerr << endl << e.what() << endl; } return 0; }