Listing 2 Illustrates stack unwinding

// destroy2.cpp
#include <iostream.h>

class Foo
{
public:
   Foo() {cout << "Foo constructor"
             << endl;}
   ~Foo() {cout << "Foo destructor"
              << endl;}
};

void f();
void g();

main()
{
   try         // Turn on exception
             // handling
   {
      f();
   }

   catch(...)  // Ellipsis matches any
             // exception
   {
      cout << "Caught exception"
          << end1;
   }
   return 0;
}

void f()
{
   Foo x;

   g();
}

void g()
{
   Foo x;

   throw 1;
}

/* Output:
Foo constructor
Foo constructor
Foo destructor
Foo destructor
Caught exception
*/

// End of File