Confusion in exception handling
<p>Consider the following program</p>

<pre><code>#include &lt;iostream&gt;
#include&lt;cstdlib&gt;
using namespace std;

class E {
   public:
      const char* error;
      E(const char* arg) : error(arg) { }
};

void my_terminate() {
  cout &lt;&lt; "Call to my_terminate" &lt;&lt; endl;
}

struct A {
  A() { cout &lt;&lt; "In constructor of A" &lt;&lt; endl; }
  ~A(){
    cout &lt;&lt; "In destructor of A" &lt;&lt; endl;
    throw E("Exception thrown in ~A()");
  }
};

struct B {
  B() { cout &lt;&lt; "In constructor of B" &lt;&lt; endl; }
  ~B() { cout &lt;&lt; "In destructor of B" &lt;&lt; endl; }
};

int main() {

  set_terminate(my_terminate);

  try {
    cout &lt;&lt; "In try block" &lt;&lt; endl;
    A a;
    B b;
    throw E("Exception thrown in try block of main()"); // Line 36
  }
  catch (E&amp; e) {
    cout &lt;&lt; "Exception: " &lt;&lt; e.error &lt;&lt; endl;
  }
  catch (...) {
    cout &lt;&lt; "Some exception caught in main()" &lt;&lt; endl;
  }

  cout &lt;&lt; "Resume execution of main()" &lt;&lt; endl;

}
</code></pre>

<p>Output:</p>

<pre><code>In try block
In constructor of A
In constructor of B
In destructor of B
In destructor of A
Call to my_terminate

Disallowed system call: SYS_kill
</code></pre>

<p>In line 36 an exception is thrown from the try block in main. Now why is this exception not caught by the handler?</p>

<p>Rather the 'stack unwinding' process continues.The destructor of A throws an exception too which is again not caught by any handler,instead a call to <code>my_terminate</code> is made, why?</p>

<p>Why is the handler not called in the two cases?</p>
