From: Mandeep Baruah Date: 2008-11-19T21:51:40+09:00 Subject: Re: "rescue Postgres::PGError" not working Erik Hollensbe wrote: > Mandeep Baruah wrote: >> I am trying to rescue exceptions from a PostgreSQL query (see bellow >> code) >> --------------------------------------------------- >> begin >> res = @pgconn.exec(querystring) # some query >> rescue Postgres::PGError => e >> puts "Error code: #{e.err}" >> puts "Error message: #{e.errstr}" >> end >> --------------------------------------------------- >> (I know that the query I am tring to execute will give an exception) >> But when I try to execute, it give me an error saying: >> "dependencies.rb:493:in `const_missing': uninitialized constant >> UpdateTestlinkDB::Postgres (NameError)" >> >> Is there a different way to handle exception or, am I missing something? > > I'm fairly certain (unless it's changed, then I have some code to push) > that the class is PGError, not Postgres::PGError. > > This would explain your error, as ruby will first search the current > namespace, then the global namespace, looking for your constant > (Postgres in this case), and will report it missing. > > -Erik I did try only with PGError, but that too does not work. I was following the steps mentioned in here (http://www.troubleshooters.com/codecorn/ruby/database/index.htm). Finally I have used 'StandardError' successfully to rescue the exception. Seems to be working now!. begin res = @pgconn.exec(querystring) # some query rescue StandardError => e puts e end Thanks!. Guys -- Posted via http://www.ruby-forum.com/.