2008/9/18 synergism <synergism / gmail.com>:
> How do we execute a handler (I assume via at_exit) when a program
> terminates *except* when there was a fatal runtime error (e.g. any
> error such as "divide by zero" that terminates the program)?

You can use exit! for this:

18:09:02 ~$ ruby -e 'at_exit { puts "exiting" }'
exiting
18:09:08 ~$ ruby -e 'at_exit { puts "exiting" }; exit 1'
exiting
18:09:14 ~$ ruby -e 'at_exit { puts "exiting" }; raise "Foo"'
exiting
-e:1: Foo (RuntimeError)
18:09:21 ~$ ruby -e 'at_exit { puts "exiting" }; exit! 1'
18:09:27 ~$

Catch specific errors and use exit! to exit the program.  Then your
handlers won't be invoked.

Cheers

robert

-- 
use.inject do |as, often| as.you_can - without end