C++20 sections · 1024 units
Open in Course

Input Validator - The Idea

Catching by type

All standard exceptions inherit from std::exception. Within that, you have logic_error (programming bugs) and runtime_error (environmental issues).

You can catch specific types or general ones. Put specific catches before general ones. If you catch std::exception first, it will catch everything and the specific catches below it will never run.

Go from most specific to least specific in your catch sequence. Use out_of_range for values outside valid bounds, invalid_argument for wrong types or formats, and runtime_error for failures during execution.

Choose the type that best describes what went wrong, helping callers respond correctly.