views:

12

answers:

1

The following line:

page_source = Net::HTTP.get(URI.parse("http://not-a-real-url.com"))

When passed a url that is properly formatted, but doesn't go anywhere (like the example above), dies out with:

getaddrinfo: nodename nor servname provided, or not known

I'm trying to figure out how to "begin / rescue" this condition, but I can't seem to find in the documentation what error, if any, the 'get' method is throwing.

+1  A: 

Does this help?

begin
  page_source = Net::HTTP.get(URI.parse("http://not-a-real-url.com"))
rescue SocketError => e
  puts e.message
end
tinifni
Ah! Worked perfectly, thank you!
normalocity