Read more

Ruby: All Errno::ERROR constants inherit from SystemCallError

Henning Koch
June 08, 2018Software engineer at makandra GmbH

To catch all possible exceptions from a network call, we need to rescue many error classes like this:

rescue SocketError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EHOSTUNREACH, OpenSSL::SSL::SSLError, MyHttpLib::BadResponse
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

You can shorten this a bit by rescuing SystemCallError Show archive.org snapshot , which is a base class for all Errno:: exceptions:

rescue SocketError, SystemCallError, OpenSSL::SSL::SSLError, MyHttpLib::BadResponse

Some high-level HTTP client libraries convert these errors into a single base class for easier handling E.g. Http.rb Show archive.org snapshot provides a HTTP::Error class and you only need to rescue this one class.

Posted by Henning Koch to makandra dev (2018-06-08 11:35)