previous | start | next

## Exception Handling

- The best remedy is to make sure that all allocated memory is deleted in a destructor.
- If a local pointer variable is unavoidable, you can use the following construct:

  >     Product* p = NULL;
  >     try
  >     {
  >        p = new Product();
  >        if (p->read())
  >        {
  >           ...
  >        }
  >        delete p;
  >     }
  >     catch(...)
  >     {
  >        delete p;
  >        throw;
  >     }

- The clause `catch(...)` matches any exception.
- The handle contains the local cleanup, followed by the `throw` statement without an exception object.
- This rethrows the exception so that the correct handler can process it.

previous | start | next