From: Mat Schaffer Date: 2006-06-24T00:25:49+09:00 Subject: Re: Global Exception Rescue On Jun 23, 2006, at 10:35 AM, James Edward Gray II wrote: > I need to run a script in a special environment. I need to change > how STDIN works, for example, to fetch responses from GUI. That's > easily done and can be made to work via a simple: > > ruby -r my_special_env script_to_run.rb > > However, one element keeps tripping me up. My special environment > must also catch exceptions not handled by the script, for error > reporting purposes. Is there any way to do the via a require? > > The best idea I have so far is to add a begin .. rescue .. end > around the code in the script and then execute it, but this seems > mighty clumsy when you take into account things like the working > directory, the script name, and line number offsets. It's doable, > but I would love to find a more elegant solution. > > Any ideas you can provide are appreciated. > > James Edward Gray II What about something like: begin load(ARGV[0]) rescue Exception => e do_stuff_with e end then: ruby my_special_env.rb script_to_run.rb Would this be unacceptable? It seems to me you could turn your environment into an app much like rcov or ruby-prof. -Mat