From: Philip Mak Date: 2002-07-19T15:46:00+09:00 Subject: Re: Can you only catch errors one level deep? On Fri, Jul 19, 2002 at 02:41:21PM +0900, Alan Chen wrote: > On Fri, Jul 19, 2002 at 10:01:29AM +0900, Philip Mak wrote: > > That's why I'm thinking that the ability to only catch errors that are > > one level deep may be useful. > > I'm still not sure what this gets you. In production code, if you're > doing extra work to only error correct one level deep, you still have > an error which will cause the program to crash with a backtrace -- > arguably the same backtrace it would have crashed with had you not > limited your rescue one level deep. The backtrace is not the same. I was installing DBI with Pgsql today, and I got this error when I tried to do DBI.connect: $ ruby -e"require 'dbi'; dbh = DBI.connect('dbi:Pg:seasft')" here /usr/local/lib/ruby/site_ruby/1.6/dbi/dbi.rb:435:in `load_driver': Could not load driver (uninitialized constant Pg at DBI::DBD) (DBI::InterfaceError) from /usr/local/lib/ruby/site_ruby/1.6/dbi/dbi.rb:349:in `_get_full_driver' from /usr/local/lib/ruby/site_ruby/1.6/dbi/dbi.rb:329:in `connect' from -e:1 That error message was not meaningful at all. I had to look at dbi.rb's code to see what was going on. I finally decided that the error was being caused when dbi.rb did "require 'DBD/Pg/Pg'". So then I typed this: $ ruby -e"require 'DBD/Pg/Pg'" /usr/local/lib/ruby/site_ruby/1.6/DBD/Pg/Pg.rb:33:in `require': libpq.so.2: cannot open shared object file: No such file or directory - /usr/local/lib/ruby/1.6/i686-linux/postgres.so (LoadError) from /usr/local/lib/ruby/site_ruby/1.6/DBD/Pg/Pg.rb:33 from -e:1:in `require' from -e:1 which is what the real problem was (I didn't have libpq.so.2 in my library path). But, because dbi.rb's begin/rescue caught an error it wasn't meant to catch, the real error message got obscured. If it hadn't, I would have been able to spot the error right away instead of digging into the source code of a library (which I shouldn't have to do).