title: How to catch all exceptions as soon as they occur by just one rescue statement
body: <p>I know how to catch the exceptions but what we do is to put "rescue" after a suspicious section of a code. what if you had a lot functions sending a query to mysql through mysql2 gem and you want to catch their exceptions. One thing you can do is to put a "rescue" statement in each of them. but i want to do that just by one rescue statement. So I put a "rescue" in end of code and put all of code in a "begin" and "end" but it didn't work.</p>
  
  <p>Here is my code and as you see there is a problem in mysql query and just because of "rescue" being end of file, it doesn't catch the exception but when I put it after that query it works.</p>
  
  <pre><code>    require 'mysql2'
  require 'colored'
  
  begin
  
  def log(string)
    p "["+string.cyan+"]"
  end
  
  def err
    p "["+"FAIL".red+"]"
  end
  
  def done
    p "["+"DONE".red+"]"
  end
  
  class SqlClient
    def initialize()
      log "SqlClient/initialize"
      puts "Host: \n"
      @host = gets.strip
      puts "User: \n"
      @user = gets.strip
      puts "Pass: \n"
      @pass = gets.strip
      @client = Mysql2::Client.new(host: @host , username: @user , password: @pass)
  
    end
  
    def list_databases()
      puts "We are listing your databases(not just projects) \n \n \n "
      @client.query("ELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA").each do |row|
        p row["SCHEMA_NAME"]
      end
  
      puts "\n \n \n"
  
    end
  
  end
  
      rescue Mysql2::Error
      err
      abort
  
  end
  
  
      `query': You have an error in your SQL syntax; check the manual that corresponds to your 
  MySQL server version for the right syntax to use near 'ELECT SCHEMA_NAME FROM 
  INFORMATION_SCHEMA.SCHEMATA' at line 1 (Mysql2::Error)
  </code></pre>
  
  <p>I'm not looking for something like:</p>
  
  <pre><code>begin
    # my code
  rescue # this line is right after the code which is going to have problem and we catch it.
  
  end
  </code></pre>
  
  <p>I'm looking for something like this:</p>
  
  <pre><code>begin
    # first method
    # second method
    # thrid method
    # rest of code and etc ...
    # now this is end of file: 
  rescue
  end
  </code></pre>
  
  <p>but as you saw in my code, it didn't work.</p>
  
  <p><strong>UPDATE:</strong> I found a similar question <a href="http://www.ruby-forum.com/topic/556154" rel="nofollow">here</a> and it seems there will be no answer :| maybe this is a sort of ruby Weakness.</p>