[lexical_cast] exception type for overflow

Hi! i would expect that lexical_cast<uint16_t>("65536") and numeric_cast<uint16_t>(lexical_cast<int>("65536")) would throw the same exception boost::numeric::positive_overflow. but lexical_cast throws a bad_lexical_cast. is it possible to change lexical_cast so that it also throws positive_overflow if the error comes from the overflow and not from the lexical parsing? -Jochen

Hi Jochen, There is a lot of code which expects that failure to lexical cast will result with bad_lexical_cast exception. I don't think it's a good idea to change this behavior. Thanks! Regard, Alexey Tkachenko. Sent from my iPhone On 4 Oct, 2012, at 10:19 PM, Jochen Wilhelmy <jochen.wilhelmy@googlemail.com> wrote:
Hi!
i would expect that lexical_cast<uint16_t>("65536") and numeric_cast<uint16_t>(lexical_cast<int>("65536")) would throw the same exception boost::numeric::positive_overflow. but lexical_cast throws a bad_lexical_cast.
is it possible to change lexical_cast so that it also throws positive_overflow if the error comes from the overflow and not from the lexical parsing?
-Jochen
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

2012/10/4 Alexey Tkachenko <iskaspb@gmail.com>:
Hi Jochen, There is a lot of code which expects that failure to lexical cast will result with bad_lexical_cast exception. I don't think it's a good idea to change this behavior. Thanks!
Regard, Alexey Tkachenko.
Alexey is right. But I can create an exception that derives from bad_lexical_cast, for example bad_lexical_cast_overflow. However it is a huge amount of work (it requires implementation of all float types casts in lexical_cast library without streams and C libraries usage and rewriting about 1k of code lines). I`ll keep in mind your proposal, but it won't be implemented in nearest releases. -- Best regards, Antony Polukhin
participants (3)
-
Alexey Tkachenko
-
Antony Polukhin
-
Jochen Wilhelmy