previous | start | next

## Preconditions

- What should a function do when called with an inappropriate value (e.g. `sqrt(-1)`)?
  - A function can fail safely. For example, the `digit_name` function simply returns an empty string when it is called with an unexpected value.
  - A function can terminate. Many functions in the `cmath` library will terminate if given an illegal value.
- The most brutal method is to print a message and terminate the entire program.
- C++ has a very sophisticated mechanism called an exception.
- Whenever possible, it is desirable to avoid termination of the program (although that is hard).
- We will discuss using `assert()`.

previous | start | next