Can someone explain what the differences between range_error , out_of_range and the pair of overflow_error and underflow_error are when I should use them? It seems they are all the same.
According to cppreference.com :
out_of_range : it reports errors that result from trying to access elements from a specific range.range_error : it reports errors that occur because the floating point value cannot be represented in some calculations because it is too large or too small. If the value is an integral type, use std::underflow_error or std::overflow_error .overflow_error : it reports errors that occur because the integer value cannot be represented in some calculation, because it has too much positive value.
In particular, I have a function,
template<typename T> void write_integer(const T &n) { if(n < 0) { throw ??? } if(some_limit < n) { throw ??? }
Where T is an integral type; the function does some border checking on n to see if it is in a certain range; if it is not, I would like to make some kind of exception. I am confused because:
out_of_range sounds like for indexing and checking the bounds of an array, which I am not doing.range_error look like a float? (But why, in C ++?)underflow_error and overflow_error ? Do they really fit?
source share