From: Eric Hodel Date: 2011-02-03T09:29:48+09:00 Subject: Re: How to know the exit status within at_exit() block? On Feb 2, 2011, at 06:34, Iñaki Baz Castillo wrote: > You are right, however I've realized that in case of exiting without > invoking "exit" or "exit!" (i.e. exiting due to a signal) then $! is > not a SystemExit instance, but an Interrupt instance (and it doesn't > have "status" method). > > For example: > > -------------------- > at_exit { p "$!.inspect = #{$!.inspect}" } > > sleep 10 > -------------------- > > If you run this program and press Ctrl+C prior to 10 seconds you get: > > "$!.inspect = Interrupt" > > So, at_exit block is executed but $! is not a SystemExit instance. I > could trap the signals however. Yes, if SystemExit === $! then … end