class length_error;
1
2
3
4
class length_error : public logic_error {
public:
explicit length_error (const string& what_arg);
};
1
2
3
4
5
class length_error : public logic_error {
public:
explicit length_error (const string& what_arg);
explicit length_error (const char* what_arg);
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// length_error example
#include <iostream> // std::cerr
#include <stdexcept> // std::length_error
#include <vector> // std::vector
int main (void) {
try {
// vector throws a length_error if resized above max_size
std::vector<int> myvector;
myvector.resize(myvector.max_size()+1);
}
catch (const std::length_error& le) {
std::cerr << "Length error: " << le.what() << '\n';
}
return 0;
}
Length error: vector::_M_fill_insert