问题描述
我的项目包含共享库和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:
这篇关于GCC程序中没有发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!