GCC程序中没有发生异常 [英] Exceptions are not caught in GCC program

查看:164
本文介绍了GCC程序中没有发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目包含共享库和exe客户端。我发现从库中抛出的我自己的异常类不被客户端catch块捕获,并且程序以抛出一个...的实例后调用终止消息终止。继续玩项目,我发现任何类型的任何异常都不会被捕获。例如,此catch不起作用:

My project contains shared library and exe client. I found that my own exception class thrown from the library is not caught by client catch block, and program terminates with "terminate called after throwing an instance of ..." message. Continuing to play with the project, I found that any exception of any type is not caught. For example, this catch doesn't work:


    try
    {
        m_pSerialPort = new boost::asio::serial_port(m_IoService, "non-existing-port");
    }
    catch(const boost::system::system_error& e)
    {
        // ...
    }

错误消息:


terminate called after throwing an instance of 
'boost::exception_detail::clone_impl
<boost::exception_detail::error_info_injector
<boost::system::system_error> >'
  what():  No such file or directory

GCC版本是4.4.1,Linux操作系统。同样的代码在Windows,MSVC中成功运行。
什么原因可以防止GCC程序正确捕获异常?

GCC version is 4.4.1, Linux OS. The same code is running successfully in Windows, MSVC. What reason can prevent GCC program to catch exceptions properly?

推荐答案

客户端.exe和共享库与libgcc链接,以便跨越共享库边界。按照GCC手册:

Both the client .exe and the shared library should to be linked with libgcc in order to throw across shared library boundaries. Per the GCC manual:


...如果库或主可执行文件应该抛出或捕获异常,则必须使用G ++或GCJ驱动程序,适用于程序中使用的语言,或使用选项-shared-libgcc,以便它与共享libgcc链接。

... if a library or main executable is supposed to throw or catch exceptions, you must link it using the G++ or GCJ driver, as appropriate for the languages used in the program, or using the option -shared-libgcc, such that it is linked with the shared libgcc.

这篇关于GCC程序中没有发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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