VC++ 2008/2010: is throw() or __declspec(nothrow) a better choice?

℡╲_俬逩灬. 提交于 2019-12-11 08:56:20

问题


When using VC++ 2008 and 2010, which marker is better to use to indicate a function won't throw exceptions:

  • throw() (C++ standard)
  • __declspec(nothrow) (MS extension)

I read a few older forum discussions where people said that using throw() may actually force the compiler to generate additional code to catch exceptions in case the function does throw (against the marker). Their advice is not to use throw() but use __declspec(nothrow) instead, since the compiler can actually use it for optimization.

I did some searches but I couldn't come up with really useful results. From how I understand, the Boost library advises against using them here. __declspec(nothrow) is non-standard C++, so if MS implements exception specifications, it'll keep working the same way while the throw() behavior may change.


回答1:


The standard form is noexcept, but VC++ 2008 and 2010 don't support this.

Personally, I'd use a macro, defined as throw() (or maybe even nothing) until compilers start supporting C++11 noexcept, and then change it.



来源:https://stackoverflow.com/questions/9040089/vc-2008-2010-is-throw-or-declspecnothrow-a-better-choice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!