Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can boost::lexical_cast<std::string>(Int_Type) ever throw?

Tags:

c++

boost

Is it possible that boost::lexical_cast<std::string>(Int_Type) throw? The only time I can think of where there will be no mem for string but can there be any other, more reasonable choices?

like image 285
smallB Avatar asked Oct 24 '22 19:10

smallB


1 Answers

According to the documentation, lexical_cast can throw bad_lexical_cast. On top of that, as you already mentioned, there may be dynamic allocation, which can always cause a bad_alloc exception.

Edit: As for the particular situation lexical_cast<std::string, int>, it seems unlikely that any part along the chain could fail other than by allocation error, but the documentation doesn't (to my knowledge) guarantee that there won't be a "bad cast" exception.

like image 81
Kerrek SB Avatar answered Oct 26 '22 23:10

Kerrek SB