title: Can I use std::current_exception during stack unwinding?
body: <p>Should it be possible to use std::current_exception inside destructors of objects that are destroyed during stack unwinding?</p>
  
  <p><a href="http://en.cppreference.com/w/cpp/error/current_exception" rel="noreferrer">Documentation on cppreference</a> says:</p>
  
  <blockquote>
    <p>If called during exception handling (typically, in a catch clause), captures the current exception object (...)</p>
  </blockquote>
  
  <p>But it's not clear for me whether stack unwinding is a part of exception handling.</p>
  
  <p>In some <a href="https://stackoverflow.com/a/18963673/200121">highest-ranked answer</a> on stackoverflow author assumes that it's possible.</p>
  
  <p>I did some test on my compiler (g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2) and it seems, that std::current_exception returns empty pointer in this case.</p>
  
  <pre><code>#include &lt;exception&gt;
  #include &lt;stdexcept&gt;
  #include &lt;iostream&gt;
  
  
  struct A
  {
      ~A()
      {
          std::clog &lt;&lt; "in destructor"&lt;&lt;std::endl;
          std::clog &lt;&lt; "uncaught_exception: " &lt;&lt; std::uncaught_exception() &lt;&lt; std::endl;
          std::clog &lt;&lt; "current_exception: " &lt;&lt; (bool)std::current_exception() &lt;&lt; std::endl;
      }
  };
  
  int main(int argc, char **)
  {
      try
      {
          A aa;
          std::clog &lt;&lt; "before throw"&lt;&lt;std::endl;
          if(argc&gt;1)
              throw std::runtime_error("oh no");
      }
      catch(...)
      {
          std::clog &lt;&lt; "in catch block"&lt;&lt;std::endl;
          std::clog &lt;&lt; "uncaught_exception: " &lt;&lt; std::uncaught_exception() &lt;&lt; std::endl;
          std::clog &lt;&lt; "current_exception: " &lt;&lt; (bool)std::current_exception() &lt;&lt; std::endl;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>before throw
  in destructor
  uncaught_exception: 1
  current_exception: 0
  in catch block
  uncaught_exception: 0
  current_exception: 1
  </code></pre>
  
  <p>Does anybody know what the standard says?</p>