On Tue, Oct 05, 2004 at 02:22:20AM +0900, Simon Conrad-Armes wrote:
> db = SQLite::Database.new('temp')
...
> ensure
>     db.close if defined? db

Just a minor point, but db is *always* defined at that point in the code,
and so this test is useless. It's defined even if an exception is raised
*before* the statement which assigns to db (see example below).

You want:

      db.close if db
or
      db.close unless db.nil?

(depending on stylistic preference). Or with a database backend, maybe
something like

      db.close if db and db.connected?

(I don't know if sqlite has a method like this though)

Regards,

Brian.
-------- 8< -------------------
begin
  raise "wibble"
  ert = 3
rescue Exception
  p defined?(ert)   # => "local-variable"
  p ert             # => nil
end