Ruby: All Errno::ERROR constants inherit from SystemCallError

Updated . Posted . Visible to the public.

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

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 provides a HTTP::Error class and you only need to rescue this one class.

Henning Koch
Last edit
Jonas Schiele
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2018-06-08 09:35)