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? The exception you are rescuing is not the one you actualyl got. Here the exception is NameError, which is not a subclass of Postgres::PGError, so it falls through the rescue clause. You *could* rescue a NameError in a separate rescue clause. Or you could rescue StandardError (common run-time exceptions) or Exception (all exceptions). However I'm pretty sure that's not what you want here. Ruby is telling you that line 493 of dependencies.rb is trying to access a constant 'Postgres' which does not exist at this time. Perhaps this means you didn't require the postgres library before this code was run. So it's more fundamental than Postgres not liking the SQL you sent to it; it's that it couldn't even send the SQL in the first place because the library isn't available. -- Posted via http://www.ruby-forum.com/.