Hello,
I'm looking to satisfy a curiosity of mine. As a preface, Consider the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream>
#include <stdexcept>
#include <vector>
int main() {
std::vector<int> vector(10);
try {
vector.at(20) = 1;
}
catch (const std::out_of_range& error) {
std::cerr << error.what() << std::endl;
}
return 0;
}
|
The
<stdexcept>
header contains the standard exceptions, which inherit from
std::exception
. Each of them has a unique generic message, which is achieved by overriding the
what
member function.
For example:
std::out_of_range
is a standard exception, whose
what
returns "invalid vector<T> subscript" when invoked, like in my example above.
Standard exceptions are very handy for this reason. The standard gives us these generic messages to use in our code, so that we don't have to roll with our own implementations (since these exceptions can be common occurrences).
Question: Does there exist, within the standard, a list of generic messages to be used for trivial, not-exceptional errors? For example, if the user is prompted to enter an integer, but enters something else ("Please enter an integer:\t" / "Try again:\t")? This is purely in the interest of keeping my code as generic as possible.
I looked into the message catalogs found in
<locale>
, but I'm not sure that's what I'm after. Any help is appreciated.