If a system call fails, I would like to throw an exception that contains the ‘errno’ relating to the failure. Right now, I use this:
if (bind(...) == -1) {
std::stringstream s;
s << "Error:" << errno << " during bind";
throw std::runtime_error(s.str());
}
That seems clumsy. I cannot directly append an integer to an std::string() – what is the best solution for this? Java has String().append(int), but there’s no such facility in std::string. Does everyone write a wrapper around std::string for this purpose?
boost::lexical_castis useful in this scenario: