本文介绍了C ++ 11异常的析构函数允许抛出现在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 任何想法为什么 virtual〜exception()throw()是在C ++ 98,,但 virtual〜exception()在C ++ 11? 设计决策允许C ++ 11抛出类异常?的析构函数? 从这里: c ++ 98: 类别例外{ public: exception()throw(); exception(const exception&)throw(); exception& operator =(const exception&)throw(); virtual〜exception()throw(); virtual const char * what()const throw(); } c ++ 11: 类异常{ public: exception()noexcept; exception(const exception&)noexcept; exception& operator =(const exception&)noexcept; virtual〜exception(); virtual const char * what()const noexcept; } 解决方案 没有这样的设计决定(幸运!)。在C ++ 11中,默认情况下,即使明确声明的析构函数也被限定为 noexcept 。这可以从C ++ 11标准的第12.4 / 3节中看出: 从第15.4 / 14节开始,它规定了隐式声明的异常规范:请注意,动态异常规范(例如 throw() C ++ 11。根据附件D的§D.4 / 1: any idea whyvirtual ~exception() throw() is in C++98,butvirtual ~exception() is in C++11?What's the design decision that allows C++11 to throw in the destructor of the 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;} 解决方案 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:And from paragraph 15.4/14, which specifies what exception specification an implicit declaration has: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:Notice, that dynamic exception specifications (such as throw()) are deprecated in C++11. Per § D.4/1 of the Annex D: 这篇关于C ++ 11异常的析构函数允许抛出现在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-16 03:48