Exception
RubyFATALCommonCore

Base class for all Ruby exceptions

Quick Answer

Rescue StandardError or a specific subclass instead of Exception to avoid suppressing signals.

What this means

Exception is the root of the Ruby exception hierarchy. All exceptions and errors inherit from it. You should almost never rescue Exception directly, as it catches system-level signals like Interrupt and SystemExit that programs normally need to propagate.

Why it happens
  1. 1Rescuing Exception too broadly, catching signals the program should not suppress
  2. 2Explicitly raising Exception as a custom error base
  3. 3Framework code that raises Exception subclasses outside StandardError

Fix

Rescue StandardError instead

Rescue StandardError instead
begin
  risky_operation
rescue StandardError => e
  puts "Caught: #{e.message}"
end

Why this works

StandardError covers all typical application errors without intercepting OS signals like Interrupt.

Code examples
Problematic broad rescueruby
begin
  risky_operation
rescue Exception => e  # catches Interrupt, SystemExit — dangerous
  puts e.message
end
Correct narrow rescueruby
begin
  risky_operation
rescue StandardError => e
  puts e.message
end
Inspecting hierarchyruby
puts RuntimeError.ancestors
# => [RuntimeError, StandardError, Exception, ...]
Sources
Official documentation ↗

Ruby Core Documentation

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

← All Ruby errors