title: std::thread and exception handling
body: <p>I am having an issue handling exceptions in multithreaded c++ code. The following program exits with <code>terminate called without an active exception Aborted (core dumped)</code>.</p>
  
  <pre><code>#include &lt;thread&gt;
  #include &lt;iostream&gt;
  #include &lt;stdexcept&gt;
  
  struct Thing {
  
      void runComponent()
      {
         throw std::runtime_error("oh no!\n");
      }
  
      void runController()
      {
          while (true) {}
      }
  
      void run()
      {
          auto control_thread = std::thread([this] { runController(); });
  
          runComponent();
  
          if (control_thread.joinable())
              control_thread.join();
      }
  };
  
  int main() 
  {
      try {
          Thing thing;
          thing.run();
      } catch (std::runtime_error &amp;ex) {
          std::cerr &lt;&lt; ex.what();
      }
  }
  </code></pre>
  
  <p>Instead, I would like to handle the exception in the <code>try catch</code> block in <code>main()</code>. I understand that exceptions are not (normally) passed between threads since threads each have there own stack. The issue here (it seems to me) is that the exception is not being handled even though it is being generated on the non-forked thread. If I comment out the lines in <code>run()</code> having to do with <code>control_thread</code>, everything works fine.</p>
  
  <p>Compiled with clang-3.8 and <code>-std=c++11 main.cpp -lpthread</code>.</p>