Synopsis: | Don't use exception specifications, but do use noexcept when applicable |
Language: | C++ |
Severity Level: | 1 |
Category: | Error Handling |
Description: |
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:
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. |