【发布时间】:2014-08-15 15:31:49
【问题描述】:
当我运行如下所示的简单程序时,我在 Cygwin 和 Ubuntu 操作系统上得到不同的终端输出。
#include <cstdio>
#include <stdexcept>
#include <cmath>
using namespace std;
double square_root(double x)
{
if (x < 0)
throw out_of_range("x<0");
return sqrt(x);
}
int main() {
const double input = -1;
double result = square_root(input);
printf("Square root of %f is %f\n", input, result);
return 0;
}
在 Cygwin 上,与 Ubuntu 不同,我没有收到任何表明引发异常的消息。这可能是什么原因?我需要为 Cygwin 下载一些东西,以便它按应有的方式处理异常吗?
我正在使用带有 GCC 4.9.0 的 Cygwin 版本 1.7.30 。在 Ubuntu 上,我有版本 13.10 和 GCC 4.8.1 。我怀疑编译器的差异在这种情况下很重要。
【问题讨论】:
-
遇到同样的问题,谢谢。
标签: c++ ubuntu gcc cygwin outofrangeexception