title: Rails: Catch Exception for Invalid SQL Query
body: <p>I allow my user to enter a custom SQL query in an advanced form if he wants, and I feed his input straight into the "where" clause in my search method.</p>
  
  <p>However, of course, sometimes the user will enter an invalid SQL query. Right now, this causes an error page to come up. I want it to instead display an "invalid syntax" statement.</p>
  
  <pre><code>def self.search(search)
      if search
          begin 
            includes(:hobbies, :games).where(search)
          rescue SQL_syntax_error_exception # ?
            #display error message
          end
  </code></pre>
  
  <p>I'm puzzled by this because even when I tried the (supposedly) all-inclusive</p>
  
  <pre><code>rescue =&gt; e
  </code></pre>
  
  <p>it still didn't catch it...</p>