Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Socket::ResolutionError#error_code

error_code → integer

Returns the raw error code indicating the cause of the hostname resolution failure.

Example
begin
  Addrinfo.getaddrinfo("ruby-lang.org", nil)
rescue Socket::ResolutionError => e
  if e.error_code == Socket::EAI_AGAIN
    puts "Temporary failure in name resolution."
  end
end

Note that error codes depend on the operating system.

also in 4.1 · 4.0 · 3.3