在Cygwin上执行的程序不会报告抛出的异常 [英] Program executed on Cygwin does not report a thrown exception

查看:162
本文介绍了在Cygwin上执行的程序不会报告抛出的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行如下所示的简单程序时,在Cygwin和Ubuntu OS上将获得不同的终端输出.

When I run a simple program shown below, I get different terminal output on Cygwin and Ubuntu OS.

#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下载一些东西,以便按预期的方式处理异常吗?

On Cygwin, unlike Ubuntu, I do not get any message indicating that an exception was thrown. What could be the reason for that? Is there something I need to download for Cygwin so that it deals with exceptions as it is supposed to?

我正在使用带有GCC 4.9.0的Cygwin版本1.7.30.在Ubuntu上,我具有带有GCC 4.8.1的13.10版本.我怀疑在这种情况下编译器的差异是否重要.

I am using Cygwin version 1.7.30 with GCC 4.9.0 . On Ubuntu, I have version 13.10 with GCC 4.8.1 . I doubt that difference in compilers matters in this case.

推荐答案

由于未捕获到异常,因此行为取决于实现/运行时.对于Linux和cygwin,这似乎以不同的方式实现.

Since you do not catch the exception, behaviour depends on the implementation/runtime. This seems to be implemented differently for Linux and cygwin.

您应该自己捕获异常,或使用这个问题.

You should catch the exception yourself, or use something as explained in the answers to this question.

这篇关于在Cygwin上执行的程序不会报告抛出的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆