TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  ERR#006Checked automatically with code checker

Synopsis:Don't use exception specifications, but do use noexcept when applicable
Severity Level:1
Category:Error Handling


Exception specifications are a way to state what kind of exceptions are thrown by a function, e.g.

int Gunc() throw(); // will throw nothing 
int Hunc() throw(A,B); // can only throw A or B

There are a couple of disadvantages with this approach:

  • Exception specifications are not checked compile-time. If a function appears to throw another exception as specified in the exception specification then a run-time error will occur that can't be caught.
  • Exception specifications are only allowed for plain functions. It won't work for typedefs for instance.
  • Exception specifications result in run-time overhead, thus affecting performance

This is the reason why exception specifications have been deprecated in C++11. The keyword "noexcept(boolean)" has been introduced instead to indicate that a function might throw or won't throw an exception, depending on the value of the boolean, e.g.

int Gunc() noexcept(true); // will throw nothing 
int Gunc() noexcept; // same as previous one
int Hunc() noexcept(false); // may throw an exception

Note that this standard doesn't enforce the use of "noexcept", it only deprecates the use of exception specifications.