std::out_of_range exception is not thrown
问题 // The following code works fine, throwing a std::out_of_range exception: std::vector<double> vd{ 1.5 }; try { int i{ -1 }; double d = vd.at(i); // exception is thrown } catch (std::out_of_range& re) { std::cout << "Exception is " << re.what() << std::endl; // invalid vector subscript } If I access vector elements in a for loop with an invalid index, no std::exception is thrown although I use .at() . Why is the std::out_of_range exception not thrown? // in a for loop, this does not throw the