previous | start | next

## Exception Handling

- If any of the functions in the `try` clause throw a `logic_error`, or call another function that throws such an exception, then the code in the catch clause executes immediately.

  >     while (more)
  >     {
  >        try
  >        {
  >           code
  >        }
  >        catch (logic_error& e)
  >        {
  >           cout << "A logic error has occurred "
  >              << e.what() << "\n"
  >              << "Retry? (y/n)";
  >           string input;
  >           getline(cin, input);
  >           if (input == "n" more = false;
  >        }
  >     }

- The `what` member function of the `locic_error` class returns the string that was passed to the constructor of the error object in the throw statement.

previous | start | next