title: cURL couldn't resolve host How to deal with that?
body: <p>I am working on a C++ program, which uses cURL lib. When I try to connect to URL, that is incorrect or the page is down I get following error :</p>
  
  <ul>
  <li>getaddrinfo(3) failed for www.wp.pl#:80</li>
  <li>Couldn't resolve host 'www.wp.pl#'</li>
  </ul>
  
  <p>And the program terminates. And that is the problem, because I it to go futher and connect to other pages. I just won't parse and analyze the broken page I don't want to end my program after come across such one.</p>
  
  <p>I posted similar topic, but it contained only snippets of code so it was diffcult for you to say what is wrong, now I will post whole code.</p>
  
  <pre><code>  int PageHandler::getCleanAndRepairedPage(string pageURL, string&amp; outDoc)
      throw (exception) {
  
  if (find(visitedPages.begin(), visitedPages.end(), pageURL)
          != visitedPages.end()) {
  
      // url has already been visited
      outDoc = "";
      return VISITED_PAGE_ERROR;
  
  } else { // new url
  
      visitedPages.push_back(pageURL);
  
      char *charURL;
  
      charURL = const_cast&lt;char*&gt; (pageURL.c_str());
  
      CURL *curl;
  
      char curl_errbuf[CURL_ERROR_SIZE];
  
      TidyBuffer output = { 0 };
      TidyBuffer errbuf = { 0 };
      TidyBuffer docbuf = { 0 };
  
      TidyDoc tdoc = tidyCreate(); // Initialize "document"
      tidyOptSetBool(tdoc, TidyForceOutput, yes);
      tidyOptSetInt(tdoc, TidyWrapLen, 4096);
      tidyBufInit(&amp;docbuf);
  
      int rc = -1;
      Bool ok;
  
      curl = curl_easy_init();
  
      curl_easy_setopt( curl, CURLOPT_URL, charURL );
  
      curl_easy_setopt( curl, CURLOPT_ERRORBUFFER, curl_errbuf );
      curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, write_cb );
      curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
      curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
      curl_easy_setopt( curl , CURLOPT_WRITEDATA, &amp;docbuf );
  
      int err;
  
      err = curl_easy_perform(curl);
  
      cout &lt;&lt; "curl_easy_perfom return value = " &lt;&lt; err &lt;&lt; endl;
  
      if (!err) {
  
          ok = tidyOptSetBool(tdoc, TidyXhtmlOut, yes); // Convert to XHTML
  
          if (ok) {
  
              rc = tidySetErrorBuffer(tdoc, &amp;errbuf); // Capture diagnostics
  
              if (rc &gt;= 0) {
  
                  rc = tidyParseBuffer(tdoc, &amp;docbuf); // parse the buffer
              }
              if (rc &gt;= 0) {
  
                  rc = tidyCleanAndRepair(tdoc); // Tidy it up!
              }
              if (rc &gt;= 0) {
  
                  rc = tidyRunDiagnostics(tdoc); // Kvetch
              }
              if (rc &gt; 1) { // If error, force output.
  
                  rc = (tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1);
              }
              if (rc &gt;= 0) {
  
                  rc = tidySaveBuffer(tdoc, &amp;output); // Pretty Print
              }
          }
  
          if (rc &gt;= 0) {
  
              if (rc &gt; 0) {
  
                  //printf("\nDiagnostics:\n\n%s", errbuf.bp);
              }
  
          } else {
  
              printf("A severe error (%d) occurred.\n", rc);
          }
  
      } else {
  
          printf("%s\n", curl_errbuf);
      }
  
      if (err == NO_ERROR) {
          string tmp(reinterpret_cast&lt;char const*&gt; (output.bp));
          outDoc = tmp;
      } else {
          outDoc = "";
      }
  
      curl_easy_cleanup(curl);
  
      tidyBufFree(&amp;docbuf);
      tidyBufFree(&amp;output);
      tidyBufFree(&amp;errbuf);
      tidyRelease(tdoc);
  
      return err; // err == 0 &lt;=&gt; everything ok!
  
  }
  
  }
  </code></pre>
  
  <p>And the console output :</p>
  
  <p>EDIT : I forgot to say what is going on on console output. I connect to many pages and the invalid URL is just one of them. At the beginning you can see a succesful connection and cURL messages about it, the result of curl_easy_perform equals 0, which indicate that everything went good. Next message is about connection to the invalid URL, as u can see return value of curl_easy_perform is 6, which is not good. 
  <img src="https://i.stack.imgur.com/Qi8uc.png" alt="Here u can see console output"></p>