From: John Maddock (jz.maddock_at_[hidden])
Date: 2019-09-20 15:31:00
On 19/09/2019 11:49, blacksmith--- via Boost wrote:
> when using boost multiprecision  to execute even simple math
> operations like addition x = x+1 or x-1 it seems on mathematical error
> it might throw either std::range_error or std::overflow_error or
> std::underflow_error .
Only range_error or overflow_error, there's no underflow_error for
checked integers - it doesn't really make sense.
> Sadly it seems that it's not the case that overflow and underflow are
> child classes of range_error.
They both inherit from runtime_error.
> So, in more complex math expression to detect any math error you must
> write catch(....) for all 3 of them (because just catching common
> std::runtime_error would be too broad and might hide some unrelated error).
What are you planning to do with the exceptions?Â Ignore them? If so you
would be better with unchecked integers?
In any case any runtime_error surely indicates something that must be
> Is there some better way for this?
> Perhaps boost should introduce a common type for math error and throw
> own under/over/range errors that inherit from std's one (for
> compatibility) and also inherit from boost::math_range_error to allow
> catch (boost::math_range_error) // either over/under flow or other math
We could I guess, it seems over-complex given that the std defines these
exception types for us.
>  for example using type like:
> boost::multiprecision::number< boost::multiprecision::cpp_int_backend<
> 64-1, 64-1, boost::multiprecision::signed_magnitude,
> boost::multiprecision::checked, void> >
--- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk