What are the pros and cons of using Exceptions vs. Error Codes?

Last updated 21 June 2026

  • Exceptions cannot be silently ignored, keep the happy path clean, and work in constructors and operators. They cost a lot when thrown (stack unwinding) and make control flow non-local, requiring RAII-based code.

  • Error codes are cheap, deterministic and explicit at each call site. They are easy to ignore (unless [[nodiscard]]) and clutter code with manual checks and propagation.

  • Use exceptions for truly exceptional failures, and codes or std::expected/std::optional for routine, expected outcomes.

  • https://www.youtube.com/watch?v=_EaCzkDPgbg
All C++ interview questions