Exception Specification Changes

C++ provides a syntax for specifying what exceptions, if any, a function may throw (refer to Chapter 15, “Friends, Exceptions, and More”):

void f501(int) throw(bad_dog);    // can throw type bad_dog exceptionvoid f733(long long) throw();     // doesn't throw an exception

As with auto_ptr, the collective experience of the C++ programming community is that, in practice, exception specifications didn’t work as well as intended. Thus, the C++11 standard deprecates exception specifications. However, the standards committee felt that there is some value in documenting that a function does not throw an exception, and it added the keyword noexcept for this purpose:

void f875(short, short) noexcept; // doesn't throw an ...

Get C++ Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.