title: How to implement proper stack unwinding and raii when thrown a bad_alloc during construction
body: <p>So I'm designing a class that's gonna be handling a bunch of memory and I want to make sure it unwinds properly if something goes wrong during memory allocation in it's constructor.</p>
  
  <p>Here's what I've got:</p>
  
  <pre><code>class foo{
  public:
      foo(): var1(nullptr), var2(nullptr){
          try{
          var1 = new int(1);
          var2 = new int(2);
          }
          catch(std::exception &amp;e){
              delete var1;
              delete var2;
              return;
          }
      //Some other things involving these variables
  }
  </code></pre>
  
  <p>Am I right in having this return in the catch block if I want to just want to stop constructing this object before some later code in the constructor causes an error because of the bad_alloc exception? Or does the catch block just cancel the constructor when it terminates? Am I overcomplicating the whole thing?</p>