Try-catch blocks cannot appear in constexpr functions
throw expressions can appear in constexpr functions
During compile-time evaluation of a constexpr function, compilation will only fail if a throw expression is hit
Guidelines
Consider using throw in constexpr functions that can fail depending on some conditions tested on the input arguments
During run-time evaluation, the exception must be caught and properly handled
During compile-time evaluation, you will get an helpful compiler error message
To check preconditions, prefer assert to throw
assert is allowed in constexpr functions since C++17
Section Summary
Learned that constant expressions are expressions that can be evaluated at compile-time
Studied that constexpr functions can be evaluated both at compile-time and run-time
Understood that C++14 constexpr functions are very flexible compared to C++11
Understood that the Standard Library does not provide many constexpr utilities, but it will in the near future
Learned that you cannot catch exceptions in constexpr functions, but you can have throw expressions in them. They will cause a compile-time error in case a code path hits them during evaluation