Boost logo

Boost :

From: blacksmith_at_[hidden]
Date: 2019-09-19 10:49:16


Hello,
when using boost multiprecision [1] 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 .

Sadly it seems that it's not the case that overflow and underflow are
child classes of range_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).

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

[1] 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> >

-- 
GPG: 31A8 55AA 07BE 5145 65EB  2292 65A6 1F7A 9781 DF89

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk