Exception Specifications Meet C++11

Sometimes an idea that seems promising in principle doesn’t work out so well in practice. Such is the story of exception specifications, a feature added by C++98 and then deprecated by C++11. That means the feature still is in the standard, but it may not be in the future, so you are encouraged not to use it.

However, before you ignore exception specifications, you at least should know what they look like. They look like this:

double harm(double a) throw(bad_thing);  // may throw bad_thing exceptiondouble marm(double) throw();             // doesn't throw an exception

The throw() part, with or without a list of types, is the exception specification, and it would appear in both the prototype and the function ...

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.