title: How to get what() and back trace at the same time for an uncaught exception?
body: <p>When an uncaught exception happens in my application, I can get the <code>what()</code> string of the exception by adding a global <code>catch</code> to my <code>main()</code> function, something like:</p>
  
  <pre><code>catch (std::exception&amp; ex)
  {
      std::cerr &lt;&lt; "Error: " &lt;&lt; ex.what() &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>I can also get the stack trace of the location where the exception was thrown by calling <code>backtrace()</code> and <code>backtrace_symbol()</code> from inside a <code>std::terminate()</code> handler (set by calling <code>std::set_terminate()</code>). For example (ignore the memory leak):</p>
  
  <pre><code>void terminate_handler()
  {
      void** buffer = new void*[15];
      int count = backtrace(buffer, 15);
      backtrace_symbols_fd(buffer, count, STDERR_FILENO);
  }
  
  …
  
  std::set_terminate(terminate_handler);
  </code></pre>
  
  <p>But when I try to combine the two approaches by rethrowing the exception using <code>throw;</code> in my global <code>catch</code>, I'm getting stack trace to that <code>catch</code>, not to the location where the exception was originally thrown.</p>
  
  <p>Is there some way I can do both (get the stack trace for the location where the exception was originally thrown and also get the value of its <code>what()</code>) at the same time?</p>