From: Robert Klemme Date: 2004-09-14T19:40:04+09:00 Subject: Re: Catching undefined global variable errors "gabriele renzi" schrieb im Newsbeitrag news:4146C099.3070601@remove-yahoo.it... > George Moschovitis ha scritto: > > > I expected that the interpreter > > would raise an Exception (undefined global or something) for > > this code. > > well, the variable is defined, just defined badly :) > for what relates to hashes, You can use an hash like this: > >> a=Hash.new { raise 'no such key' } > => {} > >> a['key'] > RuntimeError: no such key > from (irb):1 > from (irb):1:in `call' > from (irb):2:in `default' > from (irb):2:in `[]' > from (irb):2 > > so that the error does not silently goes on.. You can use #fetch for that: >> a={"here" => "there"} => {"here"=>"there"} >> a.fetch "here" => "there" >> a.fetch "not there" IndexError: key not found from (irb):7:in `fetch' from (irb):7 Regards robert