title: Ruby: How to catch custom exception in parent class when it is defined in a sub class
body: <p>I am relatively new to ruby and I am stuck with this problem which is rather hard to solve.</p>
  
  <p>What I want to achieve is that I could catch custom errors which I throw from the sub class in a parent class. Given an example below, how could I make the parent class to understand the <code>RequestTimeout</code> class? Because, now when I run the code it results to a following output:</p>
  
  <pre><code>test_raise.rb:5:in `rescue in handle_errors': uninitialized constant BaseService::RequestTimeout (NameError)
      from test_raise.rb:4:in `handle_errors'
      from test_raise.rb:14:in `first_service_method'
      from test_raise.rb:31:in `&lt;main&gt;'
  </code></pre>
  
  <p>The code:</p>
  
  <pre><code>class BaseService
  
    def handle_errors
      yield
    rescue RequestTimeout =&gt; e # &lt;-- the problem
      p e.message
    end
  end
  
  class FirstService &lt; BaseService
      class RequestTimeout &lt; StandardError; end
  
      def first_service_method
          handle_errors do
              raise RequestTimeout, "FirstService RequestTimeout"
          end
      end
  end
  
  class SecondService &lt; BaseService
      class RequestTimeout &lt; StandardError; end
  
      def second_service_method
          handle_errors do
              raise RequestTimeout, "SecondService RequestTimeout"
          end
      end
  end
  
  a = FirstService.new
  a.first_service_method
  </code></pre>
  
  <p>Ofc. I could solve the problem by changing:</p>
  
  <pre><code>rescue RequestTimeout =&gt; e
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>rescue =&gt; e
  </code></pre>
  
  <p>But I dont want to do that because I wan't to catch multiple exceptions (more than RequestTimeout) which are defined and raised by me. Any help would be awesome!</p>