lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] Use of range_error standard derivatives


From: Greg Chicares
Subject: [lmi] Use of range_error standard derivatives
Date: Sun, 19 Mar 2017 16:14:36 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0

The standard gives virtually no guidance for the use of these classes:
  range_error: "range errors in internal computations"
  overflow_error: "arithmetic overflow error"
  underflow_error: "arithmetic underflow error"
The only apparent reference to any of them in TC++PL4 actually refers
to ERANGE. I tend to conclude that any reasonable use is good.

The reason why I raise this matter now is to ask which exceptions
bourn_cast should throw. Right now, it looks like this:

    if(! to_traits::is_signed && from < 0)
        throw std::runtime_error("Cast would convert negative to unsigned.");
    if(from_traits::is_signed && from < to_traits::lowest())
        throw std::runtime_error("Cast would transgress lower limit.");
    if(to_traits::max() < from)
        throw std::runtime_error("Cast would transgress upper limit.");
    return static_cast<To>(from);

Clearly they're all runtime_errors, but should we be more specific?

Vadim, what would you say to a proposal to change those to:
        throw std::range_error("Cast would convert negative to unsigned.");
        throw std::underflow_error("Cast would transgress lower limit.");
        throw std::overflow_error("Cast would transgress upper limit.");
?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]