Urdl C++ Library

PrevUpHomeNext

Checking for errors

If we are unable to open a URL for any reason, we can find out the last error from the urdl::istream class:

urdl::istream is("http://somehost/path");
if (!is)
{
  std::cerr << "Unable to open URL: ";
  std::cerr << is.error().message() << std::endl;
  return 1;
}

Alternatively, we may test for a specific error:

// For the HTTP error codes.
#include <urdl/http.hpp>

...

urdl::istream is("http://somehost/path");
if (!is)
{
  if (is.error() == urdl::http::errc::not_found)
  {
    // Hmm, maybe we can try downloading the file from somewhere else...
  }
}

PrevUpHomeNext