【发布时间】:2012-01-30 22:50:39
【问题描述】:
我正在开发一个 C++ 程序,它使用 cURL 库,它是用纯 C 语言编写的。 当我尝试使用 cURL 句柄连接到不正确的 URL 地址时,我得到了这样的异常:
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct NULL not valid
我的程序终止,而不是跳过这个 URL 并继续前进。 这是我的代码的 sn-p:
CURL* curl;
curl_easy_setopt( curl, CURLOPT_URL, "incorrect URL" );
curl_easy_perform( curl ); // this method throws the expection
我试着这样处理:
try{
curl_easy_perform( curl );
} catch { std::logic_error &e){
return -1; // skip this URL and go futher
}
但程序仍然终止,似乎没有正确处理异常。
包含文件“stdexcept”。
有没有人知道更多关于这个错误以及如何正确捕获这个异常以便我的程序可以继续工作的信息?
【问题讨论】:
-
附加调试器并在抛出异常时发布堆栈跟踪。
-
您是否检查过
curl_easy_setopt()是否是引发异常的那个而不是curl_easy_perform()? -
不,我没有。好点子。我会在除夕晚会回来后检查它并发布结果。
-
我检查过了,setopt 一切正常。我已经在另一个主题中发布了整个代码,这是链接:stackoverflow.com/questions/8696201/…