class out_of_range;
1
2
3
4
class out_of_range : public logic_error {
public:
explicit out_of_range (const string& what_arg);
};
1
2
3
4
5
class out_of_range : public logic_error {
public:
explicit out_of_range (const string& what_arg);
explicit out_of_range (const char* what_arg);
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// out_of_range example
#include <iostream> // std::cerr
#include <stdexcept> // std::out_of_range
#include <vector> // std::vector
int main (void) {
std::vector<int> myvector(10);
try {
myvector.at(20)=100; // vector::at throws an out-of-range
}
catch (const std::out_of_range& oor) {
std::cerr << "Out of Range error: " << oor.what() << '\n';
}
return 0;
}
Out of Range error: vector::_M_range_check