Dynamic exception specification (until C++17)

Lists the exceptions that a function might directly or indirectly throw.

# Notes

Clang considers the rule of instantiation of dynamic exception specification is changed in C++11 by CWG1330, see LLVM #56349.

# Example

#include <cstdlib>
#include <exception>
#include <iostream>
 
class X {};
class Y {};
class Z : public X {};
class W {};
 
void f() throw(X, Y) 
{
    bool n = false;
 
    if (n)
        throw X(); // OK, would call std::terminate()
    if (n)
        throw Z(); // also OK
 
    throw W(); // will call std::unexpected()
}
 
void handler()
{
    std::cerr << "That was unexpected!\n"; // flush needed
    std::abort();
}
 
int main()
{
    std::set_unexpected(handler);
    f();
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
CWG 25C++98the behavior of assignment and initializationbetween pointers to members with differentexception specifications was unspecifiedapply the restrictionfor function pointersand references
CWG 973C++98exception specification may contain functions types, but thecorresponding function pointer conversion was not specifiedspecified
CWG 1330C++98an exception specification might be eagerly instantiatedit is only instantiated only if needed
CWG 1267C++11rvalue reference types were allowed in exception specificationsnot allowed
CWG 1351C++98C++11default argument (C++98) and default member initializer(C++11) were ignored in implicit exception specificationmade considered
CWG 1777C++11throw(T…) was not a non-throwingspecification even if T is an empty packit is non-throwingif the pack is empty
CWG 2191C++98the set of potential exceptions of a typeid expressionmight contain bad_typeid even if it cannot be throwncontains bad_typeidonly if it can be thrown

# See also