1234567891011121314151617
#include <iostream> #include <vector> #include <stdexcept> using namespace std; int main() { vector<int> v(4); try { v[v.size()] = 100; } catch(const exception& e){ cerr << e.what() << endl; } }
Out of Range error: vector::_M_range_check
1234
... vector<int> v(4); v[v.size()] = 100; ...
try catch
v.at(v.size()) = 100;