title: How does std::async "store" an arbitrary exception?
body: <p>I am not able to understand how is it possible for <code>std::async</code> to store any exception, not just something derived from <code>std::exception</code>. I played around with the code below</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;future&gt;
  #include &lt;chrono&gt;
  
  void f()
  {
      std::cout &lt;&lt; "\t\tIn f() we throw an exception" &lt;&lt; std::endl;
      throw 1; // throw an int
  }
  
  int main()
  {
      std::future&lt;void&gt; fut = std::async(std::launch::async, f);
      std::cout &lt;&lt; "Main thread sleeping 1s..." &lt;&lt; std::endl;
      std::this_thread::sleep_for(std::chrono::seconds(1)); // sleep one second
      std::cout &lt;&lt; "Main thread waking up" &lt;&lt; std::endl;
      try
      {
          fut.get();
      }
      catch(...)
      {
          std::cout &lt;&lt; "We caught an exception!" &lt;&lt; std::endl;
          throw; // rethrow
      }
  }
  </code></pre>
  
  <p>I launch <code>f()</code> asynchronously, then throw an <code>int</code> inside <code>f</code>. Magically, this <code>int</code> is caught and stored by the future returned by <code>std::async</code>. I understand that is possible to <code>catch(...)</code> the exception in <code>std::async</code>, but how can the latter store it without knowing the exception type? The exception is not derived from some base class (in this case one perhaps can "clone" it via some <code>Base::clone</code>), but can be any exception. Can we somehow magically "deduce" the exception type?</p>
  
  <p>To summarize, my question is:</p>
  
  <p>How can we store an arbitrary exception inside an object then re-throw it at some later time, without knowing the exception type?</p>