E
Erik Wikström
Accordin to the standard it is possible for
basic_ostream:perator<<(T val), where T is a builtin arithmetic
type, to fail (and optionally throw an exception. I've been trying to
track down what would cause << to fail but have not yet been
successful, what I really want to know is whether one should bother
looking for exceptions when using code such as this to convert
arithmetic types to strings:
template<typename T>
std::string atos(const T& v)
{
std:stringstream os;
if (!(os << v))
throw std::runtime_exception("Failed to convert value");
return os.str();
}
While I realise that it might be a good idea to check when converting
user defined types I hope/assume that there are no implementations out
there that would fail to convert the builtin arithmetic types (except
under such conditions that further execution probably will not be
possible anyway). Is this a correct assumption?
basic_ostream:perator<<(T val), where T is a builtin arithmetic
type, to fail (and optionally throw an exception. I've been trying to
track down what would cause << to fail but have not yet been
successful, what I really want to know is whether one should bother
looking for exceptions when using code such as this to convert
arithmetic types to strings:
template<typename T>
std::string atos(const T& v)
{
std:stringstream os;
if (!(os << v))
throw std::runtime_exception("Failed to convert value");
return os.str();
}
While I realise that it might be a good idea to check when converting
user defined types I hope/assume that there are no implementations out
there that would fail to convert the builtin arithmetic types (except
under such conditions that further execution probably will not be
possible anyway). Is this a correct assumption?