From: JamesBritt Date: 2002-07-19T10:42:30+09:00 Subject: RE: Can you only catch errors one level deep? > > 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. Some quick empirical study suggests that if the immediate require fails, the backtrace is of size 2, the first item giving filename:line_number:message, the second giving filename:line number If the required file itself has a require problem, then backtrace is of size 4. e.g., where faketest.rb is the main script, requiring 'fake1' (which in turn requires a nonexistent file, the root cause of the error) begin require 'fake1' rescue LoadError puts $!.backtrace.size print $!.backtrace.each_index{ |x| puts "backtrace #{x} = #{$!.backtrace[x]}"} end # prints 4 backtrace 0 = ./fake1.rb:1:in `require' backtrace 1 = ./fake1.rb:1 backtrace 2 = faketest.rb:2:in `require' backtrace 3 = faketest.rb:2 James > > > David > > -- > David Alan Black > home: dblack@candle.superlink.net > work: blackdav@shu.edu > Web: http://pirate.shu.edu/~blackdav >