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 开发者_如何学Cthe 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?
As far as I know, there is no scenario in which an inbuilt numeric type can fail to be expressed in a string.
精彩评论