Our situation is a little more complicated:

In our particular case we are creating run-time at_exit{} handlers

To give a concrete example:

We have a generic OpenOutputFile(...) routine which opens a "tentative
output" file
(output which is conditional on the module successfully completing).
We generate a temporary work file and at_exit we rename this file to
its "permanent name".
If the program aborts for any reason, this rename should not happen
( we do leave the failed working file around for later problem
investigation)



On Sep 18, 10:03=A0am, Brian Candler <b.cand... / pobox.com> wrote:
> synergism wrote:
> > 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)?
>
> "divide by zero" isn't a fatal error - you can catch it. But if you call
> "exit!" then the program will abort without running at_exit handlers.
>
> begin
> =A0 0/0
> rescue ZeroDivisionError
> =A0 exit!
> end
>
> So,if by "fatal runtime error" you just mean "any uncaught exception",
> then you can just wrap your entire program with
>
> begin
> =A0 ... rest of program
> rescue Exception
> =A0 exit!
> end
> --
> Posted viahttp://www.ruby-forum.com/.