From: David Alan Black Date: 2002-07-19T10:09:16+09:00 Subject: Re: Can you only catch errors one level deep? Hello -- On Fri, 19 Jul 2002, Philip Mak wrote: > On Fri, Jul 19, 2002 at 09:31:02AM +0900, Alan Chen wrote: > > On Fri, Jul 19, 2002 at 09:04:02AM +0900, Philip Mak wrote: > > > The problem with "rescue LoadError" is that it will also catch errors > > > it wasn't meant to! In my case, the file it loaded existed, but > > > requiring that file threw a LoadError because there was some other > > > problem with it. So the "rescue" caught an error it wasn't meant to > > > catch, and just made debugging harder. > > > > What errors did rescue LoadError catch? Where they derived from LoadError? > > It caught a LoadError that was thrown by 'require '. However, > the LoadError was thrown not because couldn't be loaded, but > because had a 'require' statement of its own which threw a > LoadError. > > I think the problem is that people see code like this: > > begin > require 'somefile' > rescue LoadError > # do something > end > > and assume that if "# do something" is executed, then it means that > 'somefile' did not exist or isn't readable. I guess you could examine the backtrace: rescue LoadError => e b = e.backtrace # now look at the size of b ... I'm sort of winging it here -- not sure if there are conditions under which this would or wouldn't work. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav