SignalException
RubyFATALCommonSystem
OS signal received by the process
Quick Answer
Use Signal.trap to handle specific signals gracefully; do not suppress SignalException in application rescue blocks.
What this means
Raised when the Ruby process receives an OS signal. Interrupt (Ctrl+C, SIGINT) is the most common subclass. Like SystemExit, SignalException is under Exception, not StandardError.
Why it happens
- 1Pressing Ctrl+C which sends SIGINT
- 2kill -TERM sent to the process from the OS or process manager
Fix
Trap specific signals for graceful shutdown
Trap specific signals for graceful shutdown
Signal.trap('TERM') do
puts 'SIGTERM received — shutting down'
$shutdown = true
end
loop do
break if $shutdown
process_next_job
endWhy this works
Signal.trap registers a handler that runs in the main thread when the signal is received.
Code examples
Interrupt from Ctrl+Cruby
begin
loop { sleep 0.1 }
rescue Interrupt
puts "
Interrupted — exiting cleanly"
endChecking ancestryruby
Interrupt < SignalException # => true SignalException < Exception # => true
Trap SIGINTruby
Signal.trap('INT') { puts 'Caught SIGINT'; exit }Same error in other languages
Sources
Official documentation ↗
Ruby Core Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev