title: How to free memory in try-catch blocks?
body: <p>I have a simple question hopefully - how does one free memory which was allocated in the try block when the exception occurs? Consider the following code:</p>
  
  <pre><code>try
   {
    char *heap = new char [50];
          //let exception occur here
    delete[] heap;
   }
   catch (...)
   {
    cout &lt;&lt; "Error, leaving function now";
    //delete[] heap; doesn't work of course, heap is unknown to compiler
    return 1;
   }
  </code></pre>
  
  <p>How can I free memory after the heap was allocated and exception occurred before calling <code>delete[] heap</code>? Is there a rule not to allocate memory on heap in these try .. catch blocks?</p>