What is the reason why std :: stof, std :: stod, std :: stold throw exceptions?
http://en.cppreference.com/w/cpp/string/basic_string/stof
Input errors are a commonly used example where error handling with exceptions is a poor fit (usually a phrase with fancy circular reasoning about “exceptional circumstances”, but still a good example). It is not as if other error handling mechanisms were somehow verbothed in the C ++ standard library. For example, another C ++ 11 newbie, the std::unordered_map::insert family, indicates a failure using the second element in the return type std::pair<iterator,bool> . Failure inside the std::unordered_map::insert function seems much more "exceptional" than an input error. Without trying to insert, you can guarantee that the insert will be successful, but indiscriminately it is impossible to guarantee that the parsing will be successful.
I'm just wondering what the rationale was at the time when these functions were accepted into the standard. I hope it is published somewhere, or a member of the committee can drop by and shed some light on this. I do not ask for a detailed treatise on the advantages and disadvantages of exceptions in comparison with other mechanisms.
source share