Boost logo

Boost :

Subject: Re: [boost] [lexical_cast] A non-throwing lexical cast? [Was: 5 Observations - My experience with the boost libraries]
From: Rene Rivera (grafikrobot_at_[hidden])
Date: 2010-03-25 13:16:49


Kim Barrett wrote:
> On Mar 24, 2010, at 5:20 PM, Bruno Santos wrote:
>> Qua, 2010-03-24 às 09:31 +0000, pete_at_[hidden] escreveu:
>>> Taking an example from way back at the start othis thread, in my
>>> personal experience a non-throwing version of lexical_cast<>
>>> would be very nice.
>>>
>>> If I look at the cases where I pass user data through my
>>> libraries into boost libraries without some pre-validation, there
>>> are very few, and naturally these are the cases where the
>>> validation would as difficult as the "parse":
>>>
>>> - boost::spirit::phrase_parse - Just returns a true/false, and I
>>> build a nice context-driven error message myself if necessary. -
>>> boost::lexical_cast - throws. Almost always needs to be caught
>>> and re-thrown.
>> Why? Is it because you need to do some cleanup? Do you known what
>> RAII is?
>
> Exception translation, i.e. "re-thrown" as in "thrown in a different
> form". boost::bad_lexical_cast is not derived from
> my_project::invalid_user_input o or whatever. This happens a lot with
> boost::lexical_cast.

So a possible improvement to the lexical_cast design would be to have an
optional template arg specifying the exception to throw for errors? Or
perhaps some other general/global way of lexical_cast looking up an
exception to throw instead of the ones it does?

-- 
-- Grafik - Don't Assume Anything
-- Redshift Software, Inc. - http://redshift-software.com
-- rrivera/acm.org (msn) - grafik/redshift-software.com
-- 102708583/icq - grafikrobot/aim,yahoo,skype,efnet,gmail

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