title: How does RAII work when a constructor throws an exception?
body: <p>I am learning about the RAII idiom in C++, and how to use smart pointers.</p>
  
  <p>In my reading, I have come across two things that, to me, seem to contradict each other.</p>
  
  <p>Quoted from <a href="http://www.hackcraft.net/raii/" rel="noreferrer">http://www.hackcraft.net/raii/</a>:</p>
  
  <blockquote>
    <p>...if a member object with RAII semantics has been created and an exception happens before the constructor has completed then its destructor will be called as part of the stack unwinding. Hence an object which controls multiple resources can guarnatee their cleanup even if it isn’t fully constructed by using member RAII objects. </p>
  </blockquote>
  
  <p>But quoted from <a href="http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.10" rel="noreferrer">http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.10</a>:</p>
  
  <blockquote>
    <p>If a constructor throws an exception, the object's destructor is not run. If your object has already done something that needs to be undone (such as allocating some memory, opening a file, or locking a semaphore), this "stuff that needs to be undone" must be remembered by a data member inside the object. </p>
  </blockquote>
  
  <p>And then the second linked source recommends using smart pointers to deal with the issue of things that were already allocated in the constructor.</p>
  
  <p>So what actually happens in these scenarios?</p>