Q:

How to get nill or messege instead of app failing when running wrong query with PG ruby

I am trying to make an SQL checker app with ruby using PG gem. Is there any way for the app to not give me an error when running a SQL that is not correct. Instead of error get nill or the error as a string. 

A:

Here's a very basic example of how to use a begin/rescue block.  
def some_method
  conn = PG.connect( dbname: 'some_db' )
  begin
   conn.exec( "MONKEY_SELECT * foo" ) # obviously not valid SQL
  rescue PG::SyntaxError
  end
end

Maybe have a look at http://rubylearning.com/satishtalim/ruby_exceptions.html 

