# class ActionDispatch::Rescue

### Public Class Methods

new(app, rescuers = {}, &block) click to toggle source

    # File lib/action_dispatch/middleware/rescue.rb, line 3
    def initialize(app, rescuers = {}, &block)
      @app, @rescuers = app, {}
      rescuers.each { |exception, rescuer| rescue_from(exception, rescuer) }
      instance_eval(&block) if block_given?
    end

### Public Instance Methods

call(env) click to toggle source

    # File lib/action_dispatch/middleware/rescue.rb, line 9
    def call(env)
      @app.call(env)
    rescue Exception => exception
      if rescuer = @rescuers[exception.class.name]
        env['action_dispatch.rescue.exception'] = exception
        rescuer.call(env)
      else
        raise exception
      end
    end

### Protected Instance Methods

rescue_from(exception, rescuer) click to toggle source

    # File lib/action_dispatch/middleware/rescue.rb, line 21
    def rescue_from(exception, rescuer)
      exception = exception.class.name if exception.is_a?(Exception)
      @rescuers[exception.to_s] = rescuer
    end