Konrad
Konrad

Reputation: 40947

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?

Upvotes: 1

Views: 4383

Answers (1)

Puppy
Puppy

Reputation: 146940

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

Upvotes: 2

Related Questions