简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM