title: c++ operator new how this works internally
body: <p>For example I have a simple code:</p>
  
  <pre><code>class B
  {
  };
  
  class A
  {
      B b;
      public:
      A()
      {
          throw 1;
      }
  };
  
  int main()
  {
      A* a = 0;
      try
      {
          a = new A;
      }
      catch (int)
      {
      }
  }
  </code></pre>
  
  <p>Constructor A throws exception, then destructor will not be called. But destructor for B will be called. Memory in the heap will not be allocated. My question how this works internally? What will be first: constructing A or allocating memory in the heap? So, if allocating is the first, how deallocating will be handled if there are exception? Othervise, if constructing A is the first, how it's copiing to the heap?   </p>