title: How to deal with bad_alloc in C++?
body: <p>There is a method called <code>foo</code> that sometimes returns the following error:</p>
  
  <pre class="lang-none prettyprint-override"><code>terminate called after throwing an instance of 'std::bad_alloc'
    what():  std::bad_alloc
  Abort
  </code></pre>
  
  <p>Is there a way that I can use a <code>try</code>-<code>catch</code> block to stop this error from terminating my program (all I want to do is return <code>-1</code>)?</p>
  
  <p>If so, what is the syntax for it?</p>
  
  <p>How else can I deal with <code>bad_alloc</code> in C++?</p>