From: DMisener Date: 2008-09-19T00:02:26+09:00 Subject: Re: at_exit handler *except* for fatal runtime error 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 am, Brian Candler 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 >   0/0 > rescue ZeroDivisionError >   exit! > end > > So,if by "fatal runtime error" you just mean "any uncaught exception", > then you can just wrap your entire program with > > begin >   ... rest of program > rescue Exception >   exit! > end > -- > Posted viahttp://www.ruby-forum.com/.