Related to Exception Handling
<blockquote>
  <p>I am trying to call terminate function.  [I think this function gets called when another exception arises during stack unwinding]. The same scenario I have written and trying to verify.  </p>
  
  <p>I am able to see a call being made to terminate() function but i am not sure why i am geting the Debug Error.</p>
  
  <p>While trying to execute the following code in Visual studio 2008, I am getting an error message dialog box "Debug Error".  The output is also being displayed:</p>
  
  <blockquote>
    <p>Output:</p>
    
    <p>In try block</p>
    
    <p>In constructor of A </p>
    
    <p>In constructor of B</p>
    
    <p>In destructor of B</p>
    
    <p>In destructor of A</p>
    
    <p>Call to my_terminate </p>
    
    <p>Why this "Debug Error" window appears while executing this code?  It is expected behavior? How to remove this error?</p>
  </blockquote>
</blockquote>

<pre><code>class E
{
public:
      const char* message;
      E(const char* arg) : message(arg) { }
};
void my_terminate() 
{
      cout &lt;&lt; "Call to my_terminate" &lt;&lt; endl;
};

class A 
{
public:
      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()");
      }
};

class B 
{
public:

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

void main() 
{
      set_terminate(my_terminate);

      try 
      {
        cout &lt;&lt; "In try block" &lt;&lt; endl;
        A a;
        B b;
        throw("Exception thrown in try block of main()");
      }
      catch (const char* e) 
      {
        cout &lt;&lt; "Exception: " &lt;&lt; e &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;
      getch();
}
</code></pre>
