, unsigned long int int . , , .
, , :
struct Exc_out_of_range {};
int make_int(const unsigned long int a) {
const int n = static_cast<int>(a);
const unsigned long int a2 = static_cast<unsigned long int>(n);
if (a2 != a) throw Exc_out_of_range();
return n;
}
, <limits>, , , , , . ( , , , , , , ).
, , , , throw , .
@GManNickG adds advice for inheriting from std::exception. I personally do not have strong feelings about this, but the advice is justified and appreciated, and I see no reason not to follow it. Here you can learn more about such inheritance.
source
share