简体   繁体   English

VS2012的异常规范

[英]Exception Specifications on VS2012

I recently updated to Visual Studio 2012 and I am having some issues with exception specifications. 我最近更新到了Visual Studio 2012,并且在异常规范方面遇到了一些问题。 I keep getting errors on system files that have the form 我不断收到以下格式的系统文件错误

<some type> function(<some input>) _NOEXCEPT    
{
  <some code>
}

where 哪里

 #define _NOEXCEPT  throw()

I don't quite understand why I get the errors, since the macro is defined and the use is as defined by Visual Studio Exception Handling . 我不太明白为什么会收到错误消息,因为定义了宏并且用法是由Visual Studio Exception Handling定义的。 The errors are something like: 错误类似于:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\list(1119): error C2059: syntax error : '{'
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\list(1119): error C2334: unexpected token(s) preceding '{'; skipping apparent function body

Lines 1118-1121 of the "list" file from above are: 上面的“列表”文件的第1118-1121行是:

const_iterator begin() const _NOEXCEPT
    {   // return iterator for beginning of nonmutable sequence
    return (const_iterator(this->_Nextnode(this->_Myhead), this));
    }

Errors come from "list" and "xtree", both located in the above path. 错误来自以上路径中的“ list”和“ xtree”。 I've tried changing the "\\EH" flag as specified in the link above but that did not help. 我尝试更改上面链接中指定的“ \\ EH”标志,但这无济于事。

Any ideas on what could be causing this? 关于什么可能导致此的任何想法?

EDIT: Adding preprocessor file excerpt. 编辑:添加预处理程序文件摘录。

const_iterator begin() const {printf("ERROR: %s\n     in file %s at line %d\n", ,"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\include\\list",1118); throw(1);}
    {   
    return (const_iterator(this->_Nextnode(this->_Myhead), this));
    }

Not sure what I should make out of this file but here is the example code. 不知道我应该用这个文件做什么,但是这里是示例代码。

EDIT 编辑

As it turns out, there was a global header with macro 事实证明,有一个带有宏的全局头

#define throw(message) {printf("ERROR: %s\n in file %s at line %d\n", message,__FILE__,__LINE__); throw(1);}

which was causing all the problems. 造成了所有问题。 undefining the macro causes things to work out nicely. 取消定义宏会使事情顺利进行。


I gave up on trying to figure this out... As a work around I redefined the _NOEXCEPT macro to not use throw, ie 我放弃了尝试解决这个问题的方法。作为解决方案,我重新定义了_NOEXCEPT宏以不使用throw,即

#define _NOEXCEPT  

in the header files that were causing problems. 在导致问题的头文件中。

I don't think it will be a major issue since all compilers ignore the exception specification and is deprecated in c++11 我认为这不会成为主要问题,因为所有编译器都会忽略异常规范,并且在c ++ 11中已弃用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM