title: C++ bad_alloc exception
body: <p>I am trying to catch the <code>bad_alloc</code> exception in order to prove that the destructors are used.</p>
  
  <p>Here is my Object:</p>
  
  <pre><code>#include "Obj.h"
  #include&lt;iostream&gt;
  using namespace std;
  
  Obj::Obj() {
  d = new double[200000000];
  }
  Obj::~Obj() {
  cout &lt;&lt; "destroyed \n";
  }
  </code></pre>
  
  <p>And the main method:</p>
  
  <pre><code>#include "Obj.h"
  #include &lt;iostream&gt;
  using namespace std;
  int main(){
  Obj* ptr[1000000];
  try{
      for(int i=0; i&lt;1000; i++){
          ptr[i] = new Obj();
      }
  } catch(bad_alloc){
      cout&lt;&lt;"EXCEPTION";
  }
  }
  </code></pre>
  
  <p>Instead of catching the exception, my program stops and tries to look for a solution online(Windows).
  Why is this happening?</p>
  
  <p><strong>EDIT</strong>
  I am getting now the exception, but I should prove that the destructor is used BEFORE the exception is thrown. How should I do that?</p>