SystemCallError
RubyERRORNotableSystem

OS system call returned an error

Quick Answer

Rescue specific Errno:: subclasses (ENOENT, EACCES) rather than SystemCallError to handle OS errors precisely.

What this means

The base class for all Errno:: errors, which map directly to POSIX errno constants. Each Errno:: subclass corresponds to a specific OS error code. Raised when Ruby calls a C-level system function that fails.

Why it happens
  1. 1File operations failing due to missing files, permissions, or disk errors
  2. 2Network operations failing due to connection refusal or timeout

Fix

Rescue specific Errno:: subclasses

Rescue specific Errno:: subclasses
begin
  File.read('/etc/protected')
rescue Errno::ENOENT
  puts 'File not found'
rescue Errno::EACCES
  puts 'Permission denied'
end

Why this works

Handling specific errno values lets you take appropriate corrective action for each OS error condition.

Code examples
Hierarchy overviewruby
Errno::ENOENT < SystemCallError  # => true
Errno::EACCES < SystemCallError  # => true
Rescue all system call errorsruby
begin
  perform_io
rescue SystemCallError => e
  puts "OS error #{e.errno}: #{e.message}"
end
Checking errno coderuby
rescue SystemCallError => e
  puts e.errno   # e.g. 2 for ENOENT, 13 for EACCES
Sources
Official documentation ↗

Ruby Core Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Ruby errors