[英]C++ cannot catch the exception thrown from curlpp in Mac OS with g++-mp-4.4
我有以下代码(由于@LokiAstari,现在可以编译):
要编译以下代码,最简单的方法是下载curlpp ,然后对其进行编译。 然后使用g ++-mp-4.4(由macport安装)编译以下代码,链接到curl和curlpp。
如果localhost:8080不存在,它将崩溃(输出: abort trap
)。 将g ++-mp-4.4更改为Xcode 4的默认值之一的g ++,它可以正常工作。
#include <string>
#include <sstream>
#include <iostream>
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
int main(int, char **)
{
try
{
curlpp::Cleanup myCleanup;
{
std::ostringstream os;
os << curlpp::options::Url("http://localhost:8080/");
}
}
catch( curlpp::RuntimeError &e )
{
std::cout << e.what() << std::endl;
}
catch( curlpp::LogicError &e )
{
std::cout << e.what() << std::endl;
}
return 0;
}
更新:
在Easy.cpp中:
void
curlpp::Easy::perform()
{
mCurl->perform(); // The exception come from here. mCurl is a std::auto_ptr<internal::CurlHandle> mCurl;
}
......
std::ostream & operator<<(std::ostream & stream, const curlpp::Easy & request)
{
// Quick clone that doesn't copy options, only the curl handle.
curlpp::Easy r(request.getCurlHandle().clone());
r.setOpt(new curlpp::options::WriteStream(& stream));
r.perform(); // The exception come from here.
return stream;
}
在CurlHandle.cpp中:
void CurlHandle::perform()
{
CURLcode code;
code = curl_easy_perform(mCurl);
throwException();
libcurlRuntimeAssert(mErrorBuffer, code); //if we got an error
}
在Exception.cpp中:
void curlpp::libcurlRuntimeAssert(const std::string & reason, CURLcode code)
{
curlpp::libcurlRuntimeAssert(reason.c_str(), code);
}
void curlpp::libcurlRuntimeAssert(const char * reason, CURLcode code)
{
if (code != CURLE_OK)
throw curlpp::LibcurlRuntimeError(reason, code);
}
我跟踪代码, throw curlpp::LibcurlRuntimeError(reason, code);
,则LibcurlRuntimeError
的构造函数很好,然后抛出,然后是SIGABRT。
堆栈跟踪:
0 __kill 0 0x7fff8213d0b6
1 abort 0 0x7fff821dd9f6
2 uw_init_context_1 0 0x101663af2
3 _Unwind_Resume 0 0x101663f38
4 operator<< Easy.cpp 118 0x10009b699
5 operator<< Options.cpp 34 0x1000948d8
6 RoleCreationTest::loadPlayerAsyncTestCase rolecreationtest.cpp 147 0x10008c714
7 RoleCreationTest::qt_metacall moc_rolecreationtest.cpp 87 0x1000acab2
8 QMetaMethod::invoke 0 0x1012e6667
各种MacPorts GCC 4.x编译器存在问题,并且捕获了异常,例如,请参阅GCC错误42159和MacPorts错误25042 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.