previous | start | next

## Exception Handling

- Consider the following function:

  >     void process_products(fstream& fs)
  >     {
  >        list<Product> products;
  >        bool more = true;
  >        while (more)
  >        {
  >           Product p;
  >           if (p.read(fs)) products.push_back(p);
  >           else more = false;
  >        }
  >        do something with products
  >     }

- If the `read` function throws an exception, the `process_products` functions halts, and the exception handling mechanism searches for an appropriate handler.
- The C++ exception handling mechanism invokes all destructors of stack objects before it abandons a function.
- In our example, the list object is destroyed, along with all `Product`s in the list.

previous | start | next