From: Harold Hausman Date: 2006-02-24T01:39:11+09:00 Subject: Re: How to evaluate file as Ruby code? I think rescue by default only catches StandardError (and descendants). Maybe: rescue Exception => ex Will catch this one? -Harold On 2/23/06, dblack@wobblini.net wrote: > Hi -- > > On Thu, 23 Feb 2006, Ronald Fischer wrote: > > >> load will load and evaluate the file, it will reload and > >> re-evaluate. > > > > This is exactly what I'm looking for (and for my problem it is > > OK that I revert to local variables). > > > > But now I have a new problem: Exceptions thrown by 'load' can not > > be caught! > > > > For example, > > > > begin > > load ".defaultpar" > > rescue > > puts "file not found" > > end > > > > If the file does not exist, I get the error message > > > > in `load': no such file to load -- .defaultpar (LoadError) > > > > Of course I can circumvent it by testing before for the existence > > of the file, but I wonder how I can find (from the Ruby specification), > > which exceptions can be caught by "rescue" and which ones can not. > > I believe rescue on its own catches RuntimeError and its descendants. > If you want to rescue something else, you can do: > > rescue LoadError > > > David > > -- > David A. Black (dblack@wobblini.net) > Ruby Power and Light (http://www.rubypowerandlight.com) > > "Ruby for Rails" chapters now available > from Manning Early Access Program! http://www.manning.com/books/black > >