Boost logo

Boost :

Subject: Re: [boost] [lexical_cast] A non-throwing lexical cast? [Was: 5 Observations - My experience with the boost libraries]
From: Kim Barrett (kab.conundrums_at_[hidden])
Date: 2010-03-25 13:07:09


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.


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