The problem is that in this code, main () may terminate before the spawned stream (f1).
Try this instead:
#include <thread> void f1() { throw(1); } int main(int argc, char* argv[]) { std::thread t(f1); t.join(); // wait for the thread to terminate }
This call completes () on Coliru (gcc).
Unfortunately, Visual Studio 2013 will directly call abort () instead of terminate () (at least in my tests) if I encounter this, so even adding a handler (using std :: set_handler ()) does not seem to work . I reported this to the VS team .
However, this code will throw an error while your source code is not guaranteed.
source share