0

In the ruby 'net/http' standard library, what exceptions can be raised by Net::Http class when using the new method?

Looking at the documentation here it's unclear what exceptions can be raised by that method. Even toggling "show source", and tracing the new method back to the start method and looking at its source, I don't see a clear indication of possible exceptions that could be raised.

Aaron Thomas
  • 5,054
  • 8
  • 43
  • 89

1 Answers1

3

Base class for Net::Http exceptions is Net::HTTPExceptions We can look up its descendants like was described in this question.

require 'net/http'

puts ObjectSpace.each_object(Class).select { |x| x < Net::HTTPExceptions }

It outputs 4 class names:

Net::HTTPFatalError
Net::HTTPServerException
Net::HTTPRetriableError
Net::HTTPError

There are also some class names for compatibility, like

# for compatibility
Net::HTTPClientException = Net::HTTPServerException

Source file can be viewed in ruby repository on in local file (change Ruby version to yours)

C:\Ruby26-x64\lib\ruby\2.6.0\net\http\exceptions.rb
Pavel Oganesyan
  • 6,774
  • 4
  • 46
  • 84
  • How do you know that is the base class for Net::Http exceptions? Where is this documented? – Aaron Thomas May 03 '20 at 21:20
  • @AaronThomas https://ruby-doc.org/stdlib-2.7.1/libdoc/net/http/rdoc/Net/HTTPExceptions.html It also stated in the source file (check last link in my answer). Basically that file (`exceptions.rb`) can answer your question without any additional actions. – Pavel Oganesyan May 04 '20 at 06:55