previous | start | next

## Exception Handling

- If an exception is thrown and no `catch` clause exists to catch it, then the program terminates with an error message.
- Because of potential dangers in throwing exceptions, a function can declare that it only throws exceptions of a certain type, or no exceptions at all.
- You can use that knowledge to make sure that it is safe to call certain functions, or to know which kinds of exceptions you program needs to catch.

  >     void process_products(fstream& fs)
  >        throw (UnexpectedEndOfFile, bad_alloc)

- A function signature can optionally be followed by the keyword `throw` and a parenthesized, comma-separated list of exception types; for example:
- To denote that a function throws no exceptions, use an empty exception list.

  >     void process_products(fstream& fs)
  >        throw ()

- A function without a `throw` specification is allowed to throw any exceptions.

previous | start | next