Handling exceptions

I'm using a web service in Ruby script and occasionally I get errors. I
want to add error handling code, but do not know how to describe the
error to Ruby. Here's the error:

GeoNames::APIError: {"message"=>"ERROR: canceling statement due to
statement timeout", "value"=>13}

What do I put after "rescue"? I can't leave it blank because I have more
than one error to capture.

Service is geonames.org BTW.

Another error I have to capture is:

GeoNames::APIError: {"message"=>"we are afraid we could not find a
neighbourhood for latitude and longitude :33.793038,-118.327683",
"value"=>15}

Thanks. Sorry returns aren't working, so no paragraphs.

···

--
Posted via http://www.ruby-forum.com/.

If it's the same error class you'd have to use the same rescue and then
test the error content after rescuing in order to deal with it
correctly.

something like this

begin
  #Code
rescue GeoNames::APIError => err
  case err.message
  when /timeout/
    # Handle 'timeout' error
  when /could not find/
    # Handle 'could not find' error
  else
    # Unhandled error
    raise err
  end
end

···

--
Posted via http://www.ruby-forum.com/.

Thank you. I didn't understand the syntax.

···

--
Posted via http://www.ruby-forum.com/.