#include #include #include //for class vector using namespace std; int main() { vector v {0, 10, 20, 30}; //subscripts go from 0 to 3 inclusive try { for (int i {0}; i < 5; ++i) { cout << v.at(i) << "\n"; //cout << v[i] wouldn't throw } } catch (out_of_range& oor) { cerr << "An exception was thrown, carrying bad news:\n"; cerr << oor.what() << "\n"; return EXIT_FAILURE; } return EXIT_SUCCESS; //Arrive here if no exception was thrown. }