Summing up several answers
By default, threads do not throw exceptions. They can, if included.
stringstream out; out.exceptions(std::ios::failbit); // throw exception if failbit gets set
According to the Apache C ++ Standard Library User Guide
The std :: ios_base :: badbit flag indicates problems with the underlying stream buffer. These problems may include the following:
Out of memory . There is no memory to create the buffer, or the buffer has a size of 0 for other reasons (for example, is provided outside the stream) or the stream cannot allocate memory for its own internal data, as is the case with std :: ios_base :: iword () and std :: ios_base :: pword ().
The base stream buffer throws an exception. A stream buffer may lose its integrity, for example, due to a lack of memory or a code conversion failure, or a recovery error from an external device. The stream buffer may indicate this loss of integrity by throwing an exception that is caught by the stream and causes the badbit to be set in the stream state.
Generally, you should keep in mind that badbit indicates an error situation that may not be recoverable, while failbit indicates a situation that may allow you to retry an unsuccessful operation.
So it seems that the safest way to do this is
string do_something(int in) { stringstream out; // This could throw a bad_alloc out << std::fixed << in; // This could set bad or fail bits if(out.good()) { return out.str(); } else { return ""; } }
This is too tedious, because according to Bad_alloc Handling , if thread creation fails, there are big problems to worry about, and the program is probably about to exit. Thus, assuming that it begins to create a stream, it is possible, but extremely unlikely, that the bit will be installed. (The thread receives the allocation with memory <sizeof (int)).
It is also unlikely that failbit will be installed (not sure if it is used to read from the stack, except for the corrupt stack). Thus, the following code is sufficient, since recovery from a stream error is currently inactive.
string do_something(int in) { stringstream out; out << std::fixed << in; return out.str(); }