Rule A15-4-1 (required, implementation, automated)

Dynamic exception-specification shall not be used.

Rationale

This feature was deprecated in the 2011 C++ Language Standard (See: Deprecating Exception Specifications). Main issues with dynamic exception specifications are: Run-time checking: Exception specifications are checked at runtime, so the program does not guarantee that all exceptions will be handled. The run-time failure mode does not lend itself to recovery. Run-time overhead: Run-time checking requires the compiler to produce additional code that hampers optimizations. Unusable in generic code: It is not possible to know what types of exceptions may be thrown from templates arguments operations, so a precise exception specification cannot be written. In place of dynamic exception-specification, use noexcept specification that allows to declare whether a function throws or does not throw exceptions. Note: std::unexpected_handler shall not be used.

Example

//% $Id: A15-4-1.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <stdexcept>
void F1() noexcept; // Compliant - note that noexcept is the same as
// noexcept(true)
void F2() throw();
// Non-compliant - dynamic exception-specification is
// deprecated
void F3() noexcept(false);
// Compliant
void F4() throw(std::runtime_error); // Non-compliant - dynamic
// exception-specification is deprecated
void F5() throw(
...); // Non-compliant - dynamic exception-specification is deprecated
template <class T>
void F6() noexcept(noexcept(T())); // Compliant

See also

C++ Core Guidelines [11]: E.12: Use noexcept when exiting a function because of a throw is impossible or unacceptable open-std.org [18]: open std Deprecating Exception Specifications mill22: A Pragmatic Look at Exception Specifications