Exception specifiers were deprecated, because exception specifiers were usually a terrible idea . noexcept was added because this is one useful use of the exception specifier: knowing when the function will not throw an exception. Thus, it becomes a binary choice: functions that will throw, and functions that will not be thrown.
noexcept , not just removing all throw specifiers other than throw() , because noexcept more powerful. noexcept may have a parameter that compile time resolves to a boolean. If the boolean value is true, then noexcept is stored. If the boolean value is false, then noexcept does not get up, and the function may discard.
So you can do something like this:
struct<typename T> { void CreateOtherClass() { T t{}; } };
Does CreateOtherClass exceptions? This may be if the default T constructor can. How do we talk? Like this:
struct<typename T> { void CreateOtherClass() noexcept(is_nothrow_default_constructible<T>::value) { T t{}; } };
Thus, CreateOtherClass() will throw an iff, which generates a default constructor of this type. This fixes one of the main issues with exception qualifiers: their inability to propagate the call stack.
You cannot do this with throw() .
Nicol Bolas Oct 11 '12 at 6:23 2012-10-11 06:23
source share