When to catch boost::bad_lexical_cast

From the documentation on the boost site for lexical cast it states that when converting from a numeric type to a string type the conversion can throw a bad_lexical_cast. Clearly in this case we should always handle this exception should it be thrown.

My question is, what about the other way around, going from a numeric type to a string? This is less risky on operation but it does not state on the boost documentation whether this operation can throw a bad_lexical_cast although the example given ommits the catch block.

log_message("Error " + boost::lexical_cast<std::string>(yoko) + ": " + strerror(yoko));

Should I be catching a potential exception when converting from a numeric type to a string?

Answers


As far as I know, there is no scenario in which an inbuilt numeric type can fail to be expressed in a string.


Need Your Help

Does it save more memory and is it more efficient to reuse recyclerviews?

java android memory-management heap

I have a total of 4 recyclerviews, each with currently has its own xml recyclerview, is it better on the memory usage to have all 4 fragments use 1 xml recyclerview or each have its own recyclervie...

How do I turn a 1x1 alias into a scalar?

apache-pig

I want to turn counts into probabilities: