Boost logo

Boost :

Subject: Re: [boost] [lexical_cast] A non-throwing lexical cast? [Was: 5 Observations - My experience with the boost libraries]
From: Bruno Santos (bsantos_at_[hidden])
Date: 2010-03-25 14:13:17


Hi,

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.
>

If the user data is data that comes from a file or user interface, I
agree in your assertion.
However, if it's from someone using your library, it's an obvious
programming error, doing exception translation in this case is
pointless.

Anyway, in my opinion, passing a boost::system::error_code as the second
parameter for a non throwing version would be the best solution.

> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


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