0Pricing
C++ Academy · Lesson

noexcept Specifier

Mark non-throwing functions.

What noexcept Declares

The noexcept specifier promises a function will not throw. If it does anyway, the program calls std::terminate.

#include <iostream>

int square(int x) noexcept {
    return x * x;
}

int main() {
    std::cout << square(5) << "\n";
}

Why It Matters

Knowing a function cannot throw lets the compiler and library optimize — for example, choosing moves over copies during container growth.

All lessons in this course

  1. try, catch, throw
  2. Exception Safety
  3. noexcept Specifier
  4. Custom Exception Types
← Back to C++ Academy