title: C++11 exception design. Idioms and best practices changed?
body: <p>I am wondering if, since C++11, where passing exceptions between threads was added and nested exceptions were added, idioms changed for exception capturing, in general.</p>
  
  <p>Now we have:</p>
  
  <ol>
  <li><code>std::rethrow_if_nested</code></li>
  <li><code>std::rethrow_with_nested</code></li>
  <li><code>std::rethrow_exception</code></li>
  <li><code>std::current_exception</code></li>
  </ol>
  
  <p>Nested exceptions are supposed to be used to not lose context for exceptions.</p>
  
  <p>So now you can do something like this:</p>
  
  <pre><code>void open_file(std::string const &amp; file_name) {
     try {
        std::ifstream file;
        file.exceptions(ios::failbit | ios::badbit);
        file.open(file_name);
     }
     catch (...) {
        std::rethrow_with_nested(std::logic_error("File " + file_name + 
        " could not be open"));
     }
  }
  </code></pre>
  
  <p>You can get the backtrace like this, if I'm not wrong:</p>
  
  <pre><code>void print_backtrace(std::exception const &amp; e, int depth = 0) {
     std::cerr &lt;&lt; std::string(depth, ' ') &lt;&lt; e.what() &lt;&lt; std::endl;
     try {
        std::rethrow_if_nested(e);
     }
     catch (std::exception const &amp; ex) {
        print_backtrace(ex, ++depth);
     }
  }
  </code></pre>
  
  <p>So if you use <code>print_backtrace</code> with <code>open_file</code> it should give you the <code>std::logic_error</code> + the <code>ios_base::failure</code> in the output.</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Is this idiom the "correct" way of handling exceptions in c++11, given that I want to capture all exceptions without losing context?</li>
  <li>Is there a way in the <code>print_backtrace</code> function to capture exceptions with <code>catch (...)</code> to capture absolutely all?</li>
  <li>I don't know why <code>std::rethrow_exception</code> is needed and I don't know when either. </li>
  </ol>