我正在尝试使用-fno-exceptions标志编译简单的代码,但出现了错误。
请告诉我如何抑制这个错误。我正在使用gcc版本4.6.3
代码
#include <iostream>
using namespace std;
int main () {
try
{
throw 20;
}
catch (int e)
{
cout << "An exception occurred. Exception Nr. " << e << '\n';
}
return 0;
}
日志
> g++ throw.cc -o out -fno-exceptions
throw.cc: In function ‘int main()’:
throw.cc:10:11: error: exception handling disabled, use -fexceptions to enable
throw.cc:14:56: error: ‘e’ was not declared in this scope
编辑
我有一个客户端代码,其中有很多类似于这样的异常。我必须将其集成到我的项目中,但我无法控制编译标志来构建(这将来自启用了-fno-exceptions的配置)。我想要一个快速的解决方法,我可以建议。
编辑
我找到了一个解决方法,请参见下面的答案。
no-exceptions
?为什么不遵循编译器的建议,改为使用-fexceptions
? - abelenky