c++ - C++11 Exception's destructor allows to throw now? -
any idea why virtual ~exception() throw() in c++98, virtual ~exception() in c++11?
what's design decision allows c++11 throw in destructor of class exception?
from here:
c++98:
class exception { public: exception () throw(); exception (const exception&) throw(); exception& operator= (const exception&) throw(); virtual ~exception() throw(); virtual const char* what() const throw(); } c++11:
class exception { public: exception () noexcept; exception (const exception&) noexcept; exception& operator= (const exception&) noexcept; virtual ~exception(); virtual const char* what() const noexcept; }
what's desing decision makes c++11 allow throw in destructor of class
exception?
there no such design decision (fortunately!). in c++11, explicitly declared destructors qualified noexcept default. can evinced paragraph 12.4/3 of c++11 standard:
a declaration of destructor not have exception-specification implicitly considered have same exception-specification implicit declaration (15.4).
and paragraph 15.4/14, specifies exception specification implicit declaration has:
an inheriting constructor (12.9) , implicitly declared special member function (clause 12) have exception-specification. if
finheriting constructor or implicitly declared default constructor, copy constructor, move constructor, destructor, copy assignment operator, or move assignment operator, implicit exception-specification specifies type-idtif , iftallowed exception-specification of function directly invoked f’s implicit definition;fallows exceptions if function directly invokes allows exceptions, ,fhas exception-specificationnoexcept(true)if every function directly invokes allows no exceptions.
together, above 2 paragraphs guarantee (given declaration quoted of exception's destructor) destructor of exception won't throw.
this explicitly stated in paragraphs 18.8.1/7-8 of c++11 standard:
virtual ~exception();7 effects: destroys object of class exception.
8 remarks: does not throw exceptions.
notice, dynamic exception specifications (such throw()) deprecated in c++11. per § d.4/1 of annex d:
the use of dynamic-exception-specifications deprecated.
Comments
Post a Comment