What's the desing decision makes C++11 allow to throw in the destructor of the class exception
?
There was no such design decision (fortunately!). In C++11, even explicitly declared destructors are qualified as noexcept
by default. This can be evinced from paragraph 12.4/3 of the C++11 Standard:
A declaration of a destructor that does not have an exception-specification is implicitly considered to have
the same exception-specification as an implicit declaration (15.4).
And from paragraph 15.4/14, which specifies what exception specification an implicit declaration has:
An inheriting constructor (12.9) and an implicitly declared special member function (Clause 12) have an
exception-specification. If f
is an inheriting constructor or an implicitly declared default constructor, copy
constructor, move constructor, destructor, copy assignment operator, or move assignment operator, its implicit
exception-specification specifies the type-id T
if and only if T
is allowed by the exception-specification
of a function directly invoked by f’s implicit definition; f
allows all exceptions if any function it directly
invokes allows all exceptions, and f
has the exception-specification noexcept(true)
if every function it directly
invokes allows no exceptions.
Together, the above two paragraphs guarantee (given the declaration you quoted of exception
's destructor) that the destructor of exception
won't throw.
This is also explicitly stated in paragraphs 18.8.1/7-8 of the C++11 Standard:
virtual ~exception();
7 Effects: Destroys an object of class exception.
8 Remarks: Does not throw any exceptions.
Notice, that dynamic exception specifications (such as throw()
) are deprecated in C++11. Per § D.4/1 of the Annex D:
The use of dynamic-exception-specifications is deprecated.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…