From: DMisener Date: 2008-09-19T01:27:29+09:00 Subject: Re: at_exit handler *except* for fatal runtime error On Sep 18, 1:03 pm, Robert Klemme wrote: > 2008/9/18 synergism : > > > 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: > ... > -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. > But out above example we want to suppress the file rename for any "unanticipated exception" -- which is just the opposite of the solution you presented :=).