title: Rails - rescue_from exception handling a exception type differently based on what method the exception is raised from
body: <p>Rails's <code>:rescue_from</code> takes in a specific exception type and a method as parameter as follow:</p>
  
  <pre><code>class ApplicationController &lt; ActionController::Base
    rescue_from User::NotAuthorized, with: :deny_access # self defined exception
    rescue_from ActiveRecord::RecordInvalid, with: :show_errors
  
    rescue_from 'MyAppError::Base' do |exception|
      render xml: exception, status: 500
    end
  
    protected
      def deny_access
        ...
      end
  
      def show_errors(exception)
        exception.record.new_record? ? ...
      end
  end
  </code></pre>
  
  <p>but this implies that it will deal with the specified exception in the same way ALL ACROSS the controller.</p>
  
  <p>What if I want to handle an exception type differently based on what method the exception is raised from, Example:</p>
  
  <pre><code>class MyController &lt; ActionController::Base
  
    def method_1
      # Do Something
    rescue MyCustomError =&gt; e
      handle_exception_for_method_1(e)
    end
  
    def method_2
      # Do Something
    rescue MyCustomError =&gt; e
      handle_exception_for_method2(e)
    end
  
  protected
  
    def handle_exception_for_method_1(exception)
      # Do Something
    end
  
    def handle_exception_for_method_2(exception)
      # Do Something
    end
  
  end
  </code></pre>
  
  <p>I have the following questions:</p>
  
  <ol>
  <li><p>Can this be done by using :rescue_from as well (with any sort of options to pass in)?</p></li>
  <li><p>If not, is there any better solution of dealing with this kind of situations?</p></li>
  <li><p>(Kind of off topic but) Is it a bad practice to handle the same type of error differently in different methods in general?</p></li>
  </ol>